pandas编程一个表有三列在原表中删除列名中包含O的所有列能否用filterregex=
可以使用.filter(regex='')来删除列名中包含O的所有列。
示例代码如下:
import pandas as pd
# 创建示例数据
df = pd.DataFrame({'A': [1, 2, 3], 'OB': [4, 5, 6], 'C': [7, 8, 9]})
# 使用 .filter(regex='') 方法删除列名中包含O的所有列
df_filtered = df.filter(regex='[^O]')
print(df_filtered)
输出结果:
A C
0 1 7
1 2 8
2 3 9
在示例中,使用[^O]的正则表达式表示不包含字母O的字符,因此可以过滤掉列名中包含O的所有列。
原文地址: https://www.cveoy.top/t/topic/cpU7 著作权归作者所有。请勿转载和采集!