0

I have a dataframe multiindexed like that:

              x                        ...          y                      
          count       mean        std  ...        50%        75%        max
dataset                                ...                                 
a         142.0  54.266100  16.769825  ...  47.535269  71.803148  97.475771
bullseye  142.0  54.268730  16.769239  ...  47.382937  72.532852  85.876229
circle    142.0  54.267320  16.760013  ...  51.025022  77.782382  85.578134
d         142.0  54.263273  16.765142  ...  46.025600  68.525675  99.487200
dots      142.0  54.260303  16.767735  ...  51.299291  82.881589  94.249328

I want to exclude just columns with mean and std. I found a way here pandas dataframe select columns in multiindex to exclude mean, but can't figure out how to exclude both 'std' and 'mean'.

df.iloc[:, [df.columns.get_level_values(1)=='mean']]

I tried for example instead of '==' , in ['mean,'std'] and many other ways with 'or' , but couldn't figure it out.

szczor1
  • 191
  • 1
  • 2
  • 12

1 Answers1

1

Use Index.isin with inverted mask by ~:

df.loc[:, ~df.columns.get_level_values(1).isin(['mean', 'std'])]
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252