how to print a groupby object

Solutions on MaxInterview for how to print a groupby object by the best coders in the world

showing results for - "how to print a groupby object"
Angela
26 Jan 2019
1import pandas as pd
2df = pd.DataFrame({'A': ['one', 'one', 'two', 'three', 'three', 'one'], 'B': range(6)})
3print(df)
4#       A  B
5#0    one  0
6#1    one  1
7#2    two  2
8#3  three  3
9#4  three  4
10#5    one  5
11
12grouped_df = df.groupby('A')
13
14for key, item in grouped_df:
15    print(grouped_df.get_group(key), "\n\n")
16
17#             A  B
18#A                
19#one   0    one  0
20#      1    one  1
21#      5    one  5
22#two   2    two  2
23#three 3  three  3
24#      4  three  4