【发布时间】:2019-01-04 10:06:17
【问题描述】:
import pandas as pd
import os
import xlrd
os.chdir('D:\python')
file_name='D:\python\\test.xlsx'
sheet='test01'
df=pd.DataFrame(pd.read_excel(file_name,sheet))
df.drop(list(df.filter(regex = 'Abc')), axis = 1, inplace = True)
df.drop(list(df.filter(regex = 'def')), axis = 1, inplace = True)
df.drop(list(df.filter(regex = 'ghi')), axis = 1, inplace = True)
df.drop(list(df.filter(regex = 'jkl')), axis = 1, inplace = True)
df.drop(list(df.filter(regex = 'mno')), axis = 1, inplace = True)
df.drop(list(df.filter(regex = 'pqr')), axis = 1, inplace = True)
我想要一个列表中的所有变量(a 到 r),以便所有上述条件在一个句子中传递。为此,我想使用循环。对此有任何建议。
【问题讨论】:
-
不清楚你在问什么......你能提供一些示例输入和输出吗?请查看如何提供minimal reproducible example
标签: python pandas for-loop while-loop