Pandas Groupby And Multiindex
Is there any opportunity in pandas to groupby data by MultiIndex? By this i mean passing to groupby function not only keys but keys and values to predefine dataframe columns? a =
Solution 1:
just reindex and fillna!
In [14]: df.groupby(['a', 'b', 'c']).size().reindex(index=mi).fillna(0)
Out[14]:
foo one dull 1
shiny 1
two dull 1
shiny 2
bar one dull 1
shiny 0
two dull 1
shiny 0
dtype: float64
Post a Comment for "Pandas Groupby And Multiindex"