Maison  >  Questions et réponses  >  le corps du texte

python - pandas dataframe怎么删除所有值都相同的一列?

比如删除以下DataFrame的后两列

   0  1  2
0  1  0  1
1  0  0  1
2  1  0  1
3  0  0  1
4  0  0  1

我现在能想到的是

df.ix[:,~((df==1).all()|(df==0).all())]

显然,如果重复的数字是2、3、4、5....,那这么写就太麻烦了

ringa_leeringa_lee2741 Il y a quelques jours860

répondre à tous(1)je répondrai

  • 大家讲道理

    大家讲道理2017-04-18 09:05:50

    df.ix[:, (df != df.ix[0]).any()]

    répondre
    0
  • Annulerrépondre