I have used following aggregation dictionary:
fare_agg = {
'Fare_amount': {
'mean_fare_amount':'mean',
'meadian_fare_amount': 'median'
},
'Total_amount':{
'mean_total_amount':'mean',
'median_total_amount':'median'
},
'Trip_distance':{
'mean_trip_distance':'mean',
'median_trip_distance':'median'
}
}
df_g = df_a.groupby('type').agg(fare_agg)
When I save the data to the csv it comes up with two level headers. I tried to remove df_a.columns = df_a.columns.droplevel(0)
but that didn't work. Then tried to reset_index(inplace=True)
but that also didn't work. Whats the trick to get only the second level header.
Here is how the csv header looks like:
type,Trip_distance,Trip_distance,Fare_amount,Fare_amount,Total_amount,Total_amount
,mean_trip_distance,median_trip_distance,mean_fare_amount,meadian_fare_amount,median_total_amount,mean_total_amount