读取Excel框架时跳过特定的一组列- pandas [英] Skip specific set of columns when reading excel frame - pandas

查看:450
本文介绍了读取Excel框架时跳过特定的一组列- pandas 的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我事先知道excel文件中不需要哪些列,并且在读取文件时希望避免使用它们以提高性能.像这样:

I know beforehand what columns I don't need from an excel file and I'd like to avoid them when reading the file to improve the performance. Something like this:

import pandas as pd
df = pd.read_excel('large_excel_file.xlsx', skip_cols=['col_a', 'col_b',...,'col_zz'])

文档中与此没有任何关系.有什么解决方法吗?

There is nothing related to this in the documentation. is there any workaround for this?

推荐答案

您可以使用以下技术:

In [7]: cols2skip = [2,5,8]

In [8]: cols = [i for i in range(10) if i not in cols2skip]

In [9]: cols
Out[9]: [0, 1, 3, 4, 6, 7, 9]

然后

df = pd.read_excel(filename, usecols=cols)

这篇关于读取Excel框架时跳过特定的一组列- pandas 的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆