📌  相关文章
📜  <pandas.core.groupby.generic.dataframegroupby object - Whatever Code Example

📅  最后修改于: 2022-03-11 14:58:47.692000             🧑  作者: Mango

代码示例1
df = pd.DataFrame({'a':[1,1,1,2,2,2,3,3,3,3],'b':np.random.randn(10)})

df
   a         b
0  1  1.048099
1  1 -0.830804
2  1  1.007282
3  2 -0.470914
4  2  1.948448
5  2 -0.144317
6  3 -0.645503
7  3 -1.694219
8  3  0.375280
9  3 -0.065624

groups = df.groupby('a')

groups # Tells you what "df.groupby('a')" is, not an error


groups.count() # count the number of 1 present in the 'a' column
   b
a   
1  3
2  3
3  4

groups.sum() # sums the 'b' column values based on 'a' grouping

          b
a          
1  1.224577
2  1.333217
3 -2.030066