Groupby.col
Obtain the column(s) per groups
danfo.Groupby.col(col_names) [source]
Parameters
Type
Description
Default
col_names
Array
List of column
Returns: Groupby Data structure
Note: This is similar to pandas df.groupby(["column"])["col_names"]
Examples
Obtain a column
Node
1
const dfd = require("danfojs-node")
2
3
let data ={'A': ['foo', 'bar', 'foo', 'bar',
4
'foo', 'bar', 'foo', 'foo'],
5
'B': ['one', 'one', 'two', 'three',
6
'two', 'two', 'one', 'three'],
7
'C': [1,3,2,4,5,2,6,7],
8
'D': [3,2,4,1,5,6,7,8]
9
}
10
11
let df = new dfd.DataFrame(data)
12
13
14
let grp = df.groupby(["A"])
15
grp.col(["C"])
16
17
//for more coumns
18
grp.col(["C","D"])
Copied!
Apparently the output are not that useful unless you perform some operations like max(), count() and the likes.
1
//it returns the groupby data structure
2
GroupBy {
3
key_col: [ 'A' ],
4
col_dict: {
5
foo: [ [Array], [Array], [Array], [Array], [Array] ],
6
bar: [ [Array], [Array], [Array] ]
7
},
8
data: [
9
[ 'foo', 'one', 1, 3 ],
10
[ 'bar', 'one', 3, 2 ],
11
[ 'foo', 'two', 2, 4 ],
12
[ 'bar', 'three', 4, 1 ],
13
[ 'foo', 'two', 5, 5 ],
14
[ 'bar', 'two', 2, 6 ],
15
[ 'foo', 'one', 6, 7 ],
16
[ 'foo', 'three', 7, 8 ]
17
],
18
column_name: [ 'A', 'B', 'C', 'D' ],
19
data_tensors: {
20
foo: DataFrame {
21
kwargs: [Object],
22
series: false,
23
data: [Array],
24
row_data_tensor: [Tensor],
25
index_arr: [Array],
26
columns: [Array],
27
col_data: [Array],
28
col_data_tensor: [Tensor],
29
col_types: [Array],
30
A: [Getter/Setter],
31
B: [Getter/Setter],
32
C: [Getter/Setter],
33
D: [Getter/Setter]
34
},
35
bar: DataFrame {
36
kwargs: [Object],
37
series: false,
38
data: [Array],
39
row_data_tensor: [Tensor],
40
index_arr: [Array],
41
columns: [Array],
42
col_data: [Array],
43
col_data_tensor: [Tensor],
44
col_types: [Array],
45
A: [Getter/Setter],
46
B: [Getter/Setter],
47
C: [Getter/Setter],
48
D: [Getter/Setter]
49
}
50
},
51
group_col_name: [ 'C' ],
52
group_col: { foo: [ [Series] ], bar: [ [Series] ] }
53
}
Copied!
Last modified 1yr ago
Copy link