With the release of Pandas 0.20.1, there is a new legacy functionality for groupby.agg () with a dictionary for renaming.
Deprecation Documentation
I am trying to find a better way to update my account code for this, however I am afraid of how I am currently using this rename function.
When I execute an aggregate, I often have several functions for each source column, and I used this rename function to go to the same 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'}})
Result:
Out[33]:
B C
foo bar bar2
A
1 3 0 2
2 7 3 4
What do I usually do then:
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
, , , . . .