Update(blocks): python新增一些pandas图形块,多语言将在稳定后进行

新增pandas API如下:
1. 值排序: sort_values()
2. 获取前 / 后n行数据: head() / tail()
3. 根据所给条件筛选数据
4. 通过给定标签分组: groupby()
5. 常用聚合函数
This commit is contained in:
王立帮
2024-09-16 02:52:18 +08:00
parent 4570a2e9ab
commit b573250af6
4 changed files with 665 additions and 345 deletions

View File

@@ -1455,4 +1455,109 @@ export const py_sum = {
this.setOutput(true);
this.setTooltip('Returns the sum of the iterable.');
}
};
};
export const dataframe_sort_values = {
init: function () {
this.setColour(DATA_HUE);
this.appendValueInput('DICT')
.setAlign(Blockly.inputs.Align.RIGHT)
.setCheck('Dict');
this.appendDummyInput()
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('值排序');
this.appendValueInput('KEY')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('标签');
this.appendDummyInput()
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('排序方式')
.appendField(new Blockly.FieldDropdown([
['升序', 'True'],
['降序', 'False']
]), 'AS_CENDING');
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip('');
}
}
export const dataframe_head_tail = {
init: function () {
this.setColour(DATA_HUE);
this.appendValueInput('DICT')
.setAlign(Blockly.inputs.Align.RIGHT)
.setCheck('Dict');
this.appendDummyInput()
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('获取')
.appendField(new Blockly.FieldDropdown([
['前几行', 'head'],
['最后几行', 'tail']
]), 'TYPE');
this.appendValueInput('LINES')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('行数');
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip('');
}
}
export const dataframe_select = {
init: function () {
this.setColour(DATA_HUE);
this.appendValueInput('DICT')
.setAlign(Blockly.inputs.Align.RIGHT)
.setCheck('Dict');
this.appendDummyInput()
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('筛选数据');
this.appendValueInput('KEY')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('满足条件');
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip('');
}
}
export const dataframe_groupby = {
init: function () {
this.setColour(DATA_HUE);
this.appendValueInput('DICT')
.setAlign(Blockly.inputs.Align.RIGHT)
.setCheck('Dict');
this.appendValueInput('KEY')
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('通过标签');
this.appendDummyInput()
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField('分组');
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip('');
}
}
export const dataframe_aggregate_func = {
init: function () {
this.setColour(DATA_HUE);
this.appendDummyInput()
.setAlign(Blockly.inputs.Align.RIGHT)
.appendField(new Blockly.FieldDropdown([
['求最小值', 'min'],
['求最大值', 'max'],
['求和', 'sum'],
['求平均值', 'mean'],
['求中位数', 'median'],
['求标准差', 'std']
]), 'TYPE');
this.appendValueInput('DICT')
.setAlign(Blockly.inputs.Align.RIGHT)
.setCheck('Dict');
this.setOutput(true);
this.setInputsInline(true);
this.setTooltip('');
}
}