📜  如何打印 groupby 对象 - Python 代码示例

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

代码示例1
import pandas as pd
df = pd.DataFrame({'A': ['one', 'one', 'two', 'three', 'three', 'one'], 'B': range(6)})
print(df)
#       A  B
#0    one  0
#1    one  1
#2    two  2
#3  three  3
#4  three  4
#5    one  5

grouped_df = df.groupby('A')

for key, item in grouped_df:
    print(grouped_df.get_group(key), "\n\n")

#             A  B
#A                
#one   0    one  0
#      1    one  1
#      5    one  5
#two   2    two  2
#three 3  three  3
#      4  three  4