Answers for "How to print a groupby object"

0

How to print a groupby object

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
Posted by: Guest on June-28-2021

Code answers related to "How to print a groupby object"

Python Answers by Framework

Browse Popular Code Answers by Language