Skip to content

Commit 1eff02b

Browse files
author
minjk-bl
committed
Add Library - Groupby > size & Data info > size
1 parent 8570eaf commit 1eff02b

5 files changed

Lines changed: 368 additions & 26 deletions

File tree

data/libraries.xml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,6 +1381,11 @@
13811381
<desc>데이터프레임 고유값 조회</desc>
13821382
<file>pandas/getUnique.js</file>
13831383
</item>
1384+
<item id="pdIdt_size" type="function" level="2" name="size" tag="데이터 크기 조회, GET SIZE, SIZE">
1385+
<path>visualpython - pandas - data info - get size</path>
1386+
<desc>판다스 객체 크기 조회</desc>
1387+
<file>pandas/getSize.js</file>
1388+
</item>
13841389
</item>
13851390
<!-- General functions -->
13861391
<item id="pd_generalFunc" type="package" level="1" name="General functions" tag="일반 함수, GENERAL FUNCTIONS">
@@ -1537,37 +1542,42 @@
15371542
<desc>데이터의 합 연산</desc>
15381543
<file>pandas/agg_sum.js</file>
15391544
</item>
1540-
<item id="pdGrp_mean" type="function" level="2" name="mean" tag="집계 연산, 평균, MEAN, MEAN">
1545+
<item id="pdGrp_mean" type="function" level="2" name="mean" tag="집계 연산, 평균, MEAN">
15411546
<path>visualpython - pandas - groupby - mean</path>
15421547
<desc>데이터의 평균값</desc>
15431548
<file>pandas/agg_mean.js</file>
15441549
</item>
1545-
<item id="pdGrp_count" type="function" level="2" name="count" tag="집계 연산, 개수, COUNT, COUNT">
1550+
<item id="pdGrp_count" type="function" level="2" name="count" tag="집계 연산, 개수, COUNT">
15461551
<path>visualpython - pandas - groupby - count</path>
15471552
<desc>데이터 개수</desc>
15481553
<file>pandas/agg_count.js</file>
15491554
</item>
1550-
<item id="pdGrp_max" type="function" level="2" name="max" tag="집계 연산, 최댓값, MAX, MAX">
1555+
<item id="pdGrp_max" type="function" level="2" name="max" tag="집계 연산, 최댓값, MAX">
15511556
<path>visualpython - pandas - groupby - max</path>
15521557
<desc>데이터의 최댓값</desc>
15531558
<file>pandas/agg_max.js</file>
15541559
</item>
1555-
<item id="pdGrp_min" type="function" level="2" name="min" tag="집계 연산, 최솟값, MIN, MIN">
1560+
<item id="pdGrp_min" type="function" level="2" name="min" tag="집계 연산, 최솟값, MIN">
15561561
<path>visualpython - pandas - groupby - min</path>
15571562
<desc>데이터의 최솟값</desc>
15581563
<file>pandas/agg_min.js</file>
15591564
</item>
1560-
<item id="pdGrp_median" type="function" level="2" name="median" tag="집계 연산, 중앙값, MEDIAN, MEDIAN">
1565+
<item id="pdGrp_median" type="function" level="2" name="median" tag="집계 연산, 중앙값, MEDIAN">
15611566
<path>visualpython - pandas - groupby - median</path>
15621567
<desc>데이터의 중앙값</desc>
15631568
<file>pandas/agg_median.js</file>
15641569
</item>
1565-
<item id="pdGrp_std" type="function" level="2" name="std" tag="집계 연산, 표준 편차, STD, STANDARD DEVIATION, STD">
1570+
<item id="pdGrp_std" type="function" level="2" name="std" tag="집계 연산, 표준 편차, STD, STANDARD DEVIATION">
15661571
<path>visualpython - pandas - groupby - std</path>
15671572
<desc>데이터의 표준편차</desc>
15681573
<file>pandas/agg_std.js</file>
15691574
</item>
1570-
<item id="pdGrp_quantile" type="function" level="2" name="quantile" tag="집계 연산, 백분위 수, QUANTILE, QUANTILE">
1575+
<item id="pdGrp_size" type="function" level="2" name="size" tag="집계 연산, 개수, SIZE">
1576+
<path>visualpython - pandas - groupby - size</path>
1577+
<desc>데이터의 크기/개수</desc>
1578+
<file>pandas/agg_size.js</file>
1579+
</item>
1580+
<item id="pdGrp_quantile" type="function" level="2" name="quantile" tag="집계 연산, 백분위 수, QUANTILE">
15711581
<path>visualpython - pandas - groupby - quantile</path>
15721582
<desc>데이터의 백분위 수</desc>
15731583
<file>pandas/agg_quantile.js</file>

src/pandas/agg.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ define([
116116
var aggTypesTag = new vpSuggestInputText.vpSuggestInputText();
117117
aggTypesTag.setComponentID('i1');
118118
aggTypesTag.addClass('vp-input');
119-
aggTypesTag.setSuggestList(function() { return [ "'sum'", "'max'", "'min'", "'mean'", "'median'", "'std'", "'count'", "'quantile'" ]; });
119+
aggTypesTag.setSuggestList(function() {
120+
return ["'sum'", "'max'", "'min'", "'mean'", "'median'", "'std'", "'size'", "'count'", "'quantile'"];
121+
});
120122
aggTypesTag.setNormalFilter(false);
121123
aggTypesTag.setValue($(this.wrapSelector('#i1')).val());
122124
$(this.wrapSelector('#i1')).replaceWith(function() {

src/pandas/agg_size.js

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
define([
2+
'require'
3+
, 'jquery'
4+
, 'nbextensions/visualpython/src/common/vpCommon'
5+
, 'nbextensions/visualpython/src/common/constant'
6+
, 'nbextensions/visualpython/src/common/StringBuilder'
7+
, 'nbextensions/visualpython/src/common/vpFuncJS'
8+
, 'nbextensions/visualpython/src/pandas/common/commonPandas'
9+
, 'nbextensions/visualpython/src/pandas/common/pandasGenerator'
10+
], function (requirejs, $, vpCommon, vpConst, sb, vpFuncJS, libPandas, pdGen) {
11+
// 옵션 속성
12+
const funcOptProp = {
13+
stepCount : 1
14+
, funcName : "Size"
15+
, funcID : "pdGrp_size" // TODO: ID 규칙 생성 필요
16+
, libID : "pd128"
17+
}
18+
19+
/**
20+
* html load 콜백. 고유 id 생성하여 부과하며 js 객체 클래스 생성하여 컨테이너로 전달
21+
* @param {function} callback 호출자(컨테이너) 의 콜백함수
22+
*/
23+
var optionLoadCallback = function(callback, meta) {
24+
// document.getElementsByTagName("head")[0].appendChild(link);
25+
// 컨테이너에서 전달된 callback 함수가 존재하면 실행.
26+
if (typeof(callback) === 'function') {
27+
var uuid = 'u' + vpCommon.getUUID();
28+
// 최대 10회 중복되지 않도록 체크
29+
for (var idx = 0; idx < 10; idx++) {
30+
// 이미 사용중인 uuid 인 경우 다시 생성
31+
if ($(vpConst.VP_CONTAINER_ID).find("." + uuid).length > 0) {
32+
uuid = 'u' + vpCommon.getUUID();
33+
}
34+
}
35+
$(vpCommon.wrapSelector(vpCommon.formatString("#{0}", vpConst.OPTION_GREEN_ROOM))).find(vpCommon.formatString(".{0}", vpConst.API_OPTION_PAGE)).addClass(uuid);
36+
37+
// 옵션 객체 생성
38+
var pdPackage = new PandasPackage(uuid);
39+
pdPackage.metadata = meta;
40+
41+
// 옵션 속성 할당.
42+
pdPackage.setOptionProp(funcOptProp);
43+
// html 설정.
44+
pdPackage.initHtml();
45+
callback(pdPackage); // 공통 객체를 callback 인자로 전달
46+
}
47+
}
48+
49+
/**
50+
* html 로드.
51+
* @param {function} callback 호출자(컨테이너) 의 콜백함수
52+
*/
53+
var initOption = function(callback, meta) {
54+
vpCommon.loadHtml(vpCommon.wrapSelector(vpCommon.formatString("#{0}", vpConst.OPTION_GREEN_ROOM)), "pandas/common/commonPandas.html", optionLoadCallback, callback, meta);
55+
}
56+
57+
/**
58+
* 본 옵션 처리 위한 클래스
59+
* @param {String} uuid 고유 id
60+
*/
61+
var PandasPackage = function(uuid) {
62+
this.uuid = uuid; // Load html 영역의 uuid.
63+
// pandas 함수
64+
this.package = libPandas._PANDAS_FUNCTION[funcOptProp.libID];
65+
}
66+
67+
68+
69+
/**
70+
* vpFuncJS 에서 상속
71+
*/
72+
PandasPackage.prototype = Object.create(vpFuncJS.VpFuncJS.prototype);
73+
74+
/**
75+
* 유효성 검사
76+
* @returns 유효성 검사 결과. 적합시 true
77+
*/
78+
PandasPackage.prototype.optionValidation = function() {
79+
return true;
80+
81+
// 부모 클래스 유효성 검사 호출.
82+
// vpFuncJS.VpFuncJS.prototype.optionValidation.apply(this);
83+
}
84+
85+
86+
/**
87+
* html 내부 binding 처리
88+
*/
89+
PandasPackage.prototype.initHtml = function() {
90+
this.showFunctionTitle();
91+
92+
this.bindOptions();
93+
94+
this.loadCss(Jupyter.notebook.base_url + vpConst.BASE_PATH + vpConst.STYLE_PATH + "pandas/commonPandas.css");
95+
}
96+
97+
/**
98+
* 선택한 패키지명 입력
99+
*/
100+
PandasPackage.prototype.showFunctionTitle = function() {
101+
$(this.wrapSelector('.vp_functionName')).text(this.package.name);
102+
}
103+
104+
/**
105+
* Pandas 기본 패키지 바인딩
106+
*/
107+
PandasPackage.prototype.bindOptions = function() {
108+
// HTML 구성
109+
pdGen.vp_showInterface(this);
110+
// if it has no additional options, remove that box
111+
if (this.package.variable == undefined || this.package.variable.length <= 0) {
112+
$(this.wrapSelector('#vp_optionBox')).closest('div.vp-accordion-container').remove();
113+
}
114+
};
115+
116+
/**
117+
* 코드 생성
118+
* @param {boolean} exec 실행여부
119+
*/
120+
PandasPackage.prototype.generateCode = function(addCell, exec) {
121+
122+
var sbCode = new sb.StringBuilder();
123+
124+
125+
// 코드 생성
126+
var result = pdGen.vp_codeGenerator(this.uuid, this.package);
127+
if (result == null) return "BREAK_RUN"; // 코드 생성 중 오류 발생
128+
sbCode.append(result);
129+
130+
// cell metadata 작성하기
131+
// pdGen.vp_setCellMetadata(_VP_CODEMD);
132+
133+
134+
if (addCell) this.cellExecute(sbCode.toString(), exec);
135+
136+
return sbCode.toString();
137+
}
138+
139+
return {
140+
initOption: initOption
141+
};
142+
});

src/pandas/common/commonPandas.js

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5279,17 +5279,17 @@ define([
52795279
code: '${o0} = pd.read_excel(${i0}${v})',
52805280
input: [
52815281
{
5282-
name:'i0',
5283-
type:'text',
5282+
name: 'i0',
5283+
type: 'text',
52845284
label: 'File Path',
52855285
component: 'file'
52865286
}
52875287
],
52885288
output: [
52895289
{
5290-
name:'o0',
5291-
type:'var',
5292-
label:'Allocate to'
5290+
name: 'o0',
5291+
type: 'var',
5292+
label: 'Allocate to'
52935293
}
52945294
],
52955295
variable: [
@@ -5308,15 +5308,15 @@ define([
53085308
code: '${i0}.to_excel(${i1}${v})',
53095309
input: [
53105310
{
5311-
name:'i0',
5312-
type:'var',
5313-
label: 'Pandas Object',
5311+
name: 'i0',
5312+
type: 'var',
5313+
label: 'Target Variable',
53145314
component: 'var_select',
53155315
var_type: ['DataFrame', 'Series']
53165316
},
53175317
{
5318-
name:'i1',
5319-
type:'text',
5318+
name: 'i1',
5319+
type: 'text',
53205320
label: 'File Path',
53215321
component: 'file'
53225322
}
@@ -5339,17 +5339,17 @@ define([
53395339
code: '${o0} = ${i0}',
53405340
input: [
53415341
{
5342-
name:'i0',
5343-
type:'var',
5342+
name: 'i0',
5343+
type: 'var',
53445344
label: 'Subset Code',
53455345
component: 'var_select',
53465346
var_type: ['DataFrame']
53475347
}
53485348
],
53495349
output: [
53505350
{
5351-
name:'o0',
5352-
type:'var',
5351+
name: 'o0',
5352+
type: 'var',
53535353
label: 'Allocate to'
53545354
}
53555355
]
@@ -5362,17 +5362,63 @@ define([
53625362
code: '${o0} = ${i0}',
53635363
input: [
53645364
{
5365-
name:'i0',
5366-
type:'var',
5365+
name: 'i0',
5366+
type: 'var',
53675367
label: 'Code',
53685368
component: 'textarea',
53695369
var_type: ['DataFrame']
53705370
}
53715371
],
53725372
output: [
53735373
{
5374-
name:'o0',
5375-
type:'var',
5374+
name: 'o0',
5375+
type: 'var',
5376+
label: 'Allocate to'
5377+
}
5378+
]
5379+
},
5380+
'pd127': {
5381+
id: 'size',
5382+
name: 'Size',
5383+
library: 'pandas',
5384+
description: 'pandas object size info',
5385+
code: '${o0} = ${i0}.size',
5386+
input: [
5387+
{
5388+
name: 'i0',
5389+
type: 'var',
5390+
label: 'Target Variable',
5391+
component: 'var_select',
5392+
var_type: ['DataFrame', 'Series', 'Index']
5393+
}
5394+
],
5395+
output: [
5396+
{
5397+
name: 'o0',
5398+
type: 'var',
5399+
label: 'Allocate to'
5400+
}
5401+
]
5402+
},
5403+
'pd128': {
5404+
id: 'groupby_size',
5405+
name: 'Size',
5406+
library: 'pandas',
5407+
description: 'groupby size info',
5408+
code: '${o0} = ${i0}.size()',
5409+
input: [
5410+
{
5411+
name: 'i0',
5412+
type: 'var',
5413+
label: 'Target Variable',
5414+
component: 'var_select',
5415+
var_type: ['GroupBy']
5416+
}
5417+
],
5418+
output: [
5419+
{
5420+
name: 'o0',
5421+
type: 'var',
53765422
label: 'Allocate to'
53775423
}
53785424
]

0 commit comments

Comments
 (0)