I am doing some non-trivial aggregation, as in the following:
aggregations = {
'x_TmId': {
'Trays': 'nunique',
'Orderlines': 'count',
},
'x_Qty': 'sum'
}
newdf = pick.groupby(['Date','x_OrderId']).agg(aggregations).reset_index(True)
at this point, aggregated data columns can be named as usual
newdf.columns
but returns something that I have not encountered before: a MultiIndex object:
MultiIndex(levels=[['x_TmId', 'x_Qty', 'x_OrderId'], ['Orderlines', 'Trays', 'sum', '']],
labels=[[2, 0, 0, 1], [3, 0, 1, 2]])
At this point, I understand that I don’t know how to name the new variables "sum" as an example? There should be some kind of similar question in stackoverflow, but it hasn't found it yet.
source
share