如何选择除 pandas 中的一列以外的所有列? [英] How to select all columns, except one column in pandas?
本文介绍了如何选择除 pandas 中的一列以外的所有列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的数据框看起来像这样:
I have a dataframe look like this:
import pandas
import numpy as np
df = DataFrame(np.random.rand(4,4), columns = list('abcd'))
df
a b c d
0 0.418762 0.042369 0.869203 0.972314
1 0.991058 0.510228 0.594784 0.534366
2 0.407472 0.259811 0.396664 0.894202
3 0.726168 0.139531 0.324932 0.906575
如何获取除column b
之外的所有列?
How I can get all columns except column b
?
推荐答案
当列不是MultiIndex时,df.columns
只是列名称的数组,因此您可以执行以下操作:
When the columns are not a MultiIndex, df.columns
is just an array of column names so you can do:
df.loc[:, df.columns != 'b']
a c d
0 0.561196 0.013768 0.772827
1 0.882641 0.615396 0.075381
2 0.368824 0.651378 0.397203
3 0.788730 0.568099 0.869127
这篇关于如何选择除 pandas 中的一列以外的所有列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文