Issue
I am trying to understand the Groupby function in Pandas using the level argument in Spyder.
def print_groups(groupobject):
for name, group in groupobject:
print (name)
print (group.head())
I have data pertaining to a two symbols starting in Jan 2012 going right up to December 2012. I have set the index to Symbol, Year, and Month for the variable mi.
mi = s4g.set_index(['Symbol','Year','Month'])
mi
What I am trying to do is use the group(level=0) argument and find that only the first five rows of the dataset appear when I run this line of code.
mig_11 = mi.groupby(level=0)
print_groups(mig_11)
I find the same thing happening when I use level = 1.
mig_11a = mi.groupby(level=1)
print_groups(mig_11a)
Even when I change it to level = 2, I still see the first 5 rows.
mig_11b = mi.groupby(level=2)
print_groups(mig_11b)
Second Pic of mig_11b enter image description here
I just don't understand why I see the first five rows for each of these groupby levels when the original data goes right up to December.
Thanks a lot in advance.
Solution
Thanks to @coldspeed.
I need to replace print (group.head()) to print (group) in the code below to see the entire dataset.
def print_groups(groupobject):
for name, group in groupobject:
print (name)
print (group.head())#Replace with print (group)
Answered By - AnalysisNerd
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.