How To Preview Rows After Using .groupby() On A Pandas Df/series
After using df.groupby(df.index.month) I would like to preview my DataFrame unfortunately .head removes the group formatting and df['col'][:3] returns the following error: --------
Solution 1:
Something like this? gb
is the GroupBy object. This prints the first 5 rows from the first 3 groups.
In [230]: gb = df.groupby(df.index.month)
In [231]: for k in gb.groups.keys()[:3]:
...: print gb.get_group(k)[:5]
Solution 2:
you can loop through test
test = df.groupby("columnTitle")
foreach in test:
printeach[0] #columnTitle valueprinteach[1] #corresponding df equivalent of df[df['columnTitle']==each[0]]
Post a Comment for "How To Preview Rows After Using .groupby() On A Pandas Df/series"