【发布时间】:2019-01-17 20:53:47
【问题描述】:
有哪些 Python3 选项可以有效地(性能和内存)提取工作表名称和给定工作表,以及从非常大的 .xlsx 文件中提取列名?
我尝试过使用熊猫:
对于使用pd.ExcelFile 的工作表名称:
xl = pd.ExcelFile(filename)
return xl.sheet_names
对于使用pd.ExcelFile的列名:
xl = pd.ExcelFile(filename)
df = xl.parse(sheetname, nrows=2, **kwargs)
df.columns
对于使用pd.read_excel 和nrows (>v23) 的列名:
df = pd.read_excel(io=filename, sheet_name=sheetname, nrows=2)
df.columns
但是,pd.ExcelFile 和 pd.read_excel 似乎都读取了内存中的整个 .xlsx,因此速度很慢。
非常感谢!
【问题讨论】:
-
没有什么方便的测试,但是
dfs = pd.read_excel(filename, sheet_name=None, nrows=0)的表现如何?您应该得到一个字典,其中工作表名称作为键,空 DataFrame 作为其值...
标签: excel python-3.x performance pandas memory