I have this pandas DataFrame df
:
df.head()
windIntensity year month day hour AOBT delay
3 2015 1 1 0 0 0.0 15.0
2 2015 1 1 0 0 0.0 10.0
2 2015 1 1 1 0 0.0 5.0
2 2015 1 1 1 0 0.0 0.0
1 2015 1 1 2 0 0.0 0.0
When I execute this code:
df = dfj.groupby(["year","hour"]).agg({'windIntensity':'mean','delay':['mean','count']}).reset_index()
I get this result:
year hour windIntensity delay
mean mean count
0 2015 0 4.239207 24.240373 857
1 2015 1 4.029024 15.770449 758
2 2015 2 3.863928 7.431322 779
3 2015 3 3.859801 4.161290 806
4 2015 4 3.782659 4.722230 6851
But how can I rename columns to get one line of column, not two lines?
Expected result:
year hour windIntensity_mean delay_mean count
0 2015 0 4.239207 24.240373 857
1 2015 1 4.029024 15.770449 758
2 2015 2 3.863928 7.431322 779
3 2015 3 3.859801 4.161290 806
4 2015 4 3.782659 4.722230 6851