删除/删除名称以X *开头的列

时间:2017-11-09 21:13:47

标签: python pandas

我有以下数据和框架:

df.drop(['logA','logB'],axis=1)

如何删除所有以" log"开头的列?我试过了df.columns.str.startswith('log'),但我想知道我是否可以使用 const char path[64] = "/storage/emulated/0/sdcard/New\ XML.xml" 做些什么。

1 个答案:

答案 0 :(得分:3)

选项1
使用loc和布尔索引

df.loc[:, ~df.columns.str.startswith('log')]

    A     B
0   1   100
1  10  1000

选项2
使用带有前瞻性正面regex

pd.DataFrame.filter
df.filter(regex='^(?!log)')

    A     B
0   1   100
1  10  1000
相关问题