使用 pd 从读取中排除列.ExcelFile().parse().



我想在使用 pd 时排除某些列的读取。ExcelFile('my.xls'(.parse((

我尝试解析的 Excel 文件有太多列无法在 usecols 参数中列出它们,因为我只需要删除引起麻烦的单个列。

有没有一种简单的方法~反转列表(我知道你不能这样做(传递给usecols或其他东西?

我们通常可以做

head = list(pd.read_csv('your.xls', nrows = 1))
df = pd.read_excel('your.xls', usecols = [col for col in head if col != 'the one drop']))

但是,为什么不读取整个文件然后drop

df = pd.read_excel('your.xls').drop('the col drop', axis = 1)

最新更新