6

从 xlsx 文件中读取数据(仅 20000 个数字)需要很长时间:

import pandas as pd
xlsxfile = pd.ExcelFile("myfile.xlsx")
data = xlsxfile.parse('Sheet1', index_col = None, header = None)

大约需要 9 秒。

如果我以 csv 格式保存相同的文件,则需要大约 25 毫秒:

import pandas as pd
csvfile = "myfile.csv"
data = pd.read_csv(csvfile, index_col = None, header = None)

这是 openpyxl 的问题还是我错过了什么?有没有其他选择?

4

1 回答 1

3

xlrd支持 .xlsx 文件,这个答案表明至少支持 .xlsx 的 xlrd 测试版比 openpyxl 更快。

当前的稳定版 Pandas (11.0) 使用 openpyxl 处理 .xlsx 文件,但在下一个版本中已更改。如果你想试一试,你可以从GitHub下载开发版本

于 2013-04-25T09:00:20.363 回答