Code
import pandas as pd
df = pd.DataFrame({'A': [1, 1, 1, 2, 2],
'B': range(5),
'C': range(5)})
df1 = df.groupby('A').B.agg({'B': ['count','nunique'],'C': ['sum','median']})
df1.columns = ["_".join(x) for x in df1.columns.ravel()]
df1 Output
B_count B_nunique C_sum C_median
A
1 3 3 3 1.0
2 2 2 7 3.5
Warning
__main__:1: FutureWarning: using a dict on a Series for aggregation
is deprecated and will be removed in a future version
This was the recommended way to groupby and rename till Pandas 0.20. What is the elegant way to achieve the same df1 output without this warning?