GroupBy对象支持迭代操作

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

---------------------

posted @ 2019-08-15 12:45  水至清明  阅读(386)  评论(0编辑  收藏  举报