grouped1 = df_obj.groupby('key1')
grouped2 = df_obj['data1'].groupby(df_obj['key1'])
1
2
# 单层分组,根据key1
for group_name, group_data in g1:
print(group_name)
print(group_data)
1
2
3
4
# 多层分组,根据key1 和 key2(http://www.amjmh.com/v/BIBRGZ_558768/)
for group_name, group_data in g2:
print(group_name)
print(group_data)
1
2
3
4
---------------------