Relative Content

Tag Archive for pythonpandasgroup-bydata-science

Selecting multiple columns (`MultiIndex` based) within a `DataFrameGroupBy`

I have a complex dataframe with multiple columns. All of them being MultiIndex based. At some point I wanted to be quite specific when it comes to estimating some metrics so I started experimenting with the .groupby method. I can manage to do the basics: 1) computing the aggregation method on the whole dataframe or 2) computing it for one specific column. However, I am interested in computing the aggreagtion method by indicating some of the names within the first column levels. This is quite easy to do when there is just a single level within the columns. In order to be understood, I created the following MRO that reproduces my idea and the errors I am getting: