原文:https://segmentfault.com/q/1010000005929330
创建一个dataframe:
import pandas as pd
from pandas import DataFrame
d2 = DataFrame({
... 'a': [1, 2, 3, 4],
... 'b': [5, 6, 7, 8],
... 'c': [9, 10, 11, 12],
... 'd': [13, 14, 15, 16]
... })
# 删除包含0和1的列
df.ix[:,~((df==1).all()|(df==0).all())]
# 删除包含第一行数值的所有列
df.ix[:, (df != df.ix[0]).any()]