[英]How to select two elements from multiindex dataframe
I have a dataframe multiindexed like that:我有一个 dataframe 这样的多索引:
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'.
我在这里找到了一种方法pandas dataframe select columns in multiindex来排除均值,但无法弄清楚如何同时排除“std”和“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.例如,我尝试
in ['mean,'std']
和许多其他方式使用'or'
代替'=='
,但无法弄清楚。
Use Index.isin
with inverted mask by ~
:通过
~
将Index.isin
与倒掩码一起使用:
df.loc[:, ~df.columns.get_level_values(1).isin(['mean', 'std'])]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.