In [1]:
import pandas as pd
d = {"a":(0,1,0,1,1),"b":(3,4,4,3,3),"c":[5,4,3,2,1]}
df = pd.DataFrame(d)
print(df)
a b c0 0 3 51 1 4 42 0 4 33 1 3 24 1 3 1
In [2]:
A=df.groupby(["a","b"])
group_data = A.groups.keys()
print(group_data)
dict_keys([(0, 3), (0, 4), (1, 3), (1, 4)])
In [3]:
A.get_group((1, 3))
gd = A.count()
print(gd)
ca b 0 3 1 4 11 3 2 4 1
In [4]:
gd.reset_index(drop=False)
Out[4]:
a b c
0 0 3 1
1 0 4 1
2 1 3 2
3 1 4 1
还可以输入200个字
蝈蝈派【海南省教改项目(Hnjg2022-80)支持】 网站版权所有
Python remained the copyright of our website