With the release of Pandas 0.20.1, there is a new deprecation of the functionality to groupby.agg() with a dictionary for renaming.
I'm trying to find best way to update my code to account for this, however I'm struggling with how I've currently been utilizing this rename functionality.
When I am doing an aggregate, I often have multiple functions for each source column, and I have been using this rename functionality to get to a single level index with these new column names.
Example:
df = pd.DataFrame({'A': [1, 1, 1, 2, 2],'B': range(5),'C': range(5)})
In [30]: df
Out[30]:
A B C
0 1 0 0
1 1 1 1
2 1 2 2
3 2 3 3
4 2 4 4
frame = df.groupby('A').agg({'B' : {'foo':'sum'}, 'C': {'bar' : 'min', 'bar2': 'max'}})
Which results in:
Out[33]:
B C
foo bar bar2
A
1 3 0 2
2 7 3 4
Which I then typically do:
frame = pd.DataFrame(frame).reset_index(col_level=1)
frame.columns = frame.columns.get_level_values(1)
frame
Out[42]:
A foo bar bar2
0 1 3 0 2
1 2 7 3 4
So I'm looking for good ways to get a result dataframe that is single level index, but has new unique column names. Where multiple columns originated from an aggregate from a single source column. Any recommendations of best approach is greatly appreciated.