Skip to content

Commit d1c2e10

Browse files
committed
fix groupby
1 parent 70e0a4c commit d1c2e10

4 files changed

Lines changed: 184 additions & 186 deletions

File tree

danfojs/src/core/frame.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Series } from "./series"
44
import * as tf from '@tensorflow/tfjs'
55
import { Utils } from "./utils"
66
import { GroupBy } from "./groupby"
7-
import { Plot } from '../plotting/plot'
7+
// import { Plot } from '../plotting/plot'
88
import { indexLoc } from '../core/indexing'
99

1010
const utils = new Utils
@@ -1895,10 +1895,10 @@ export class DataFrame extends Ndframe {
18951895
* @param {string} div Name of the div to show the plot
18961896
* @param {Object} config configuration options for making Plots, supports Plotly parameters
18971897
*/
1898-
plot(div, config = {}) {
1899-
const plt = new Plot()
1900-
plt.plot(this, div, config)
1901-
}
1898+
// plot(div, config = {}) {
1899+
// const plt = new Plot()
1900+
// plt.plot(this, div, config)
1901+
// }
19021902

19031903

19041904
/**

danfojs/src/plotting/plot.js

Lines changed: 164 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -1,166 +1,166 @@
1-
//perform plotting
2-
import { newPlot } from 'plotly.js/dist/plotly'
3-
import { Utils } from "../core/utils"
4-
import { Series } from "../core/series"
1+
// //perform plotting
2+
// import { newPlot } from 'plotly.js/dist/plotly'
3+
// import { Utils } from "../core/utils"
4+
// import { Series } from "../core/series"
55

6-
const utils = new Utils()
6+
// const utils = new Utils()
77

8-
9-
10-
/**
11-
* Plotting methods and Functions performed on Series and DataFrames
12-
*/
13-
export class Plot {
14-
constructor() { }
15-
16-
plot(ndframe, div, config) {
17-
let params = Object.keys(config)
18-
let this_config = {}
19-
20-
params.forEach(param => {
21-
this_config[param] = config[param]
22-
})
23-
24-
if (!utils.__key_in_object(config, "layout")) {
25-
this_config['layout'] = {}
26-
}
27-
28-
if (ndframe instanceof Series) {
29-
let trace = {}
30-
31-
if (this_config['type'] == 'histogram') {
32-
let x = ndframe.values
33-
trace["x"] = x
34-
} else {
35-
let y = ndframe.values
36-
trace["y"] = y
37-
}
38-
39-
params.forEach(param => {
40-
trace[param] = config[param]
41-
})
42-
newPlot(div, [trace], this_config['layout']);
43-
44-
} else {
45-
46-
//DataFrame
47-
if (utils.__key_in_object(this_config, 'x') && utils.__key_in_object(this_config, 'y')) {
48-
if (!ndframe.column_names.includes(this_config['x'])) {
49-
throw Error(`Column Error: ${this_config['x']} not found in columns`)
50-
}
51-
if (!ndframe.column_names.includes(this_config['y'])) {
52-
throw Error(`Column Error: ${this_config['y']} not found in columns`)
53-
}
54-
55-
56-
let x = ndframe[this_config['x']].values
57-
let y = ndframe[this_config['y']].values
58-
59-
let trace = {
60-
x: x,
61-
y: y,
62-
type: config["type"],
63-
mode: config["mode"],
64-
}
65-
66-
let xaxis = {}; let yaxis = {}
67-
xaxis['title'] = this_config['x']
68-
yaxis['title'] = this_config['y']
69-
70-
this_config['layout']['xaxis'] = xaxis
71-
this_config['layout']['yaxis'] = yaxis
72-
73-
74-
newPlot(div, [trace], this_config['layout']);
75-
76-
77-
} else if (this_config['type'] == 'pie') {
78-
if (!ndframe.column_names.includes(this_config['values'])) {
79-
throw Error(`Column Error: ${this_config['values']} not found in columns`)
80-
}
81-
if (!ndframe.column_names.includes(this_config['labels'])) {
82-
throw Error(`Column Error: ${this_config['labels']} not found in columns`)
83-
}
84-
let data = [{
85-
values: ndframe[this_config['values']].values,
86-
labels: ndframe[this_config['labels']].values,
87-
type: 'pie'
88-
}];
89-
90-
newPlot(div, data, this_config['layout'])
91-
92-
} else if (this_config['type'] == 'table') {
93-
let header = {}
94-
let cells = {}
95-
96-
header['values'] = ndframe.column_names
97-
cells['values'] = ndframe.col_data
98-
99-
if (this_config['header_style']) {
100-
Object.keys(this_config['header_style']).forEach(param => {
101-
header[param] = this_config['header_style'][param]
102-
})
103-
}
104-
105-
if (this_config['cell_style']) {
106-
Object.keys(this_config['cell_style']).forEach(param => {
107-
header[param] = this_config['cell_style'][param]
108-
})
109-
}
110-
var data = [{
111-
type: 'table',
112-
header: header,
113-
cells: cells
114-
}]
115-
newPlot(div, data, this_config['layout']);
116-
117-
} else if (this_config['type'] == 'box') {
118-
let cols_2_show = []
119-
let data = []
120-
121-
if (this_config['columns'] != undefined) {
122-
cols_2_show = this_config['columns']
123-
cols_2_show.forEach(col => {
124-
if (!ndframe.column_names.includes(col)) {
125-
throw Error(`Column Error: ${this_config['labels']} not found in columns`)
126-
}
127-
})
128-
} else {
129-
cols_2_show = ndframe.column_names
130-
}
131-
132-
133-
cols_2_show.forEach(col => {
134-
let col_idx = ndframe.column_names.indexOf(col)
135-
let trace = []
136-
trace['y'] = ndframe.col_data[col_idx]
137-
trace["type"] = 'box'
138-
trace["name"] = col
139-
140-
data.push(trace)
141-
})
142-
newPlot(div, data, this_config['layout']);
143-
144-
} else {
145-
//plot all
146-
let x = ndframe.index
147-
let data = []
148-
ndframe.column_names.forEach(c_name => {
149-
let trace = {}
150-
trace["x"] = x
151-
trace["y"] = ndframe[c_name].values
152-
trace['name'] = c_name
153-
params.forEach(param => {
154-
trace[param] = config[param]
155-
})
156-
data.push(trace)
157-
158-
})
159-
newPlot(div, data, this_config['layout']);
160-
}
161-
162-
163-
}
164-
}
165-
166-
}
8+
9+
10+
// /**
11+
// * Plotting methods and Functions performed on Series and DataFrames
12+
// */
13+
// export class Plot {
14+
// constructor() { }
15+
16+
// plot(ndframe, div, config) {
17+
// let params = Object.keys(config)
18+
// let this_config = {}
19+
20+
// params.forEach(param => {
21+
// this_config[param] = config[param]
22+
// })
23+
24+
// if (!utils.__key_in_object(config, "layout")) {
25+
// this_config['layout'] = {}
26+
// }
27+
28+
// if (ndframe instanceof Series) {
29+
// let trace = {}
30+
31+
// if (this_config['type'] == 'histogram') {
32+
// let x = ndframe.values
33+
// trace["x"] = x
34+
// } else {
35+
// let y = ndframe.values
36+
// trace["y"] = y
37+
// }
38+
39+
// params.forEach(param => {
40+
// trace[param] = config[param]
41+
// })
42+
// newPlot(div, [trace], this_config['layout']);
43+
44+
// } else {
45+
46+
// //DataFrame
47+
// if (utils.__key_in_object(this_config, 'x') && utils.__key_in_object(this_config, 'y')) {
48+
// if (!ndframe.column_names.includes(this_config['x'])) {
49+
// throw Error(`Column Error: ${this_config['x']} not found in columns`)
50+
// }
51+
// if (!ndframe.column_names.includes(this_config['y'])) {
52+
// throw Error(`Column Error: ${this_config['y']} not found in columns`)
53+
// }
54+
55+
56+
// let x = ndframe[this_config['x']].values
57+
// let y = ndframe[this_config['y']].values
58+
59+
// let trace = {
60+
// x: x,
61+
// y: y,
62+
// type: config["type"],
63+
// mode: config["mode"],
64+
// }
65+
66+
// let xaxis = {}; let yaxis = {}
67+
// xaxis['title'] = this_config['x']
68+
// yaxis['title'] = this_config['y']
69+
70+
// this_config['layout']['xaxis'] = xaxis
71+
// this_config['layout']['yaxis'] = yaxis
72+
73+
74+
// newPlot(div, [trace], this_config['layout']);
75+
76+
77+
// } else if (this_config['type'] == 'pie') {
78+
// if (!ndframe.column_names.includes(this_config['values'])) {
79+
// throw Error(`Column Error: ${this_config['values']} not found in columns`)
80+
// }
81+
// if (!ndframe.column_names.includes(this_config['labels'])) {
82+
// throw Error(`Column Error: ${this_config['labels']} not found in columns`)
83+
// }
84+
// let data = [{
85+
// values: ndframe[this_config['values']].values,
86+
// labels: ndframe[this_config['labels']].values,
87+
// type: 'pie'
88+
// }];
89+
90+
// newPlot(div, data, this_config['layout'])
91+
92+
// } else if (this_config['type'] == 'table') {
93+
// let header = {}
94+
// let cells = {}
95+
96+
// header['values'] = ndframe.column_names
97+
// cells['values'] = ndframe.col_data
98+
99+
// if (this_config['header_style']) {
100+
// Object.keys(this_config['header_style']).forEach(param => {
101+
// header[param] = this_config['header_style'][param]
102+
// })
103+
// }
104+
105+
// if (this_config['cell_style']) {
106+
// Object.keys(this_config['cell_style']).forEach(param => {
107+
// header[param] = this_config['cell_style'][param]
108+
// })
109+
// }
110+
// var data = [{
111+
// type: 'table',
112+
// header: header,
113+
// cells: cells
114+
// }]
115+
// newPlot(div, data, this_config['layout']);
116+
117+
// } else if (this_config['type'] == 'box') {
118+
// let cols_2_show = []
119+
// let data = []
120+
121+
// if (this_config['columns'] != undefined) {
122+
// cols_2_show = this_config['columns']
123+
// cols_2_show.forEach(col => {
124+
// if (!ndframe.column_names.includes(col)) {
125+
// throw Error(`Column Error: ${this_config['labels']} not found in columns`)
126+
// }
127+
// })
128+
// } else {
129+
// cols_2_show = ndframe.column_names
130+
// }
131+
132+
133+
// cols_2_show.forEach(col => {
134+
// let col_idx = ndframe.column_names.indexOf(col)
135+
// let trace = []
136+
// trace['y'] = ndframe.col_data[col_idx]
137+
// trace["type"] = 'box'
138+
// trace["name"] = col
139+
140+
// data.push(trace)
141+
// })
142+
// newPlot(div, data, this_config['layout']);
143+
144+
// } else {
145+
// //plot all
146+
// let x = ndframe.index
147+
// let data = []
148+
// ndframe.column_names.forEach(c_name => {
149+
// let trace = {}
150+
// trace["x"] = x
151+
// trace["y"] = ndframe[c_name].values
152+
// trace['name'] = c_name
153+
// params.forEach(param => {
154+
// trace[param] = config[param]
155+
// })
156+
// data.push(trace)
157+
158+
// })
159+
// newPlot(div, data, this_config['layout']);
160+
// }
161+
162+
163+
// }
164+
// }
165+
166+
// }

0 commit comments

Comments
 (0)