我现在使用PyExcelerator来读取excel文件,但速度非常慢.因为我总是需要打开超过100MB的excel文件,所以只需要加载一个文件就需要20多分钟.
我需要的功能是:
我现在使用的代码是:
book = pyExcelerator.parse_xls(filepath)
parsed_dictionary = defaultdict(lambda: '', book[0][1])
number_of_columns = 44
result_list = []
number_of_rows = 500000
for i in range(0, number_of_rows):
ok = False
result_list.append([])
for h in range(0, number_of_columns):
item = parsed_dictionary[i,h]
if type(item) is StringType or type(item) is UnicodeType:
item = item.replace("\t","").strip()
result_list[i].append(item)
if item != '':
ok = True
if not ok:
break
Run Code Online (Sandbox Code Playgroud)
有什么建议?
似乎没有维护pyExcelerator.要编写xls文件,请使用xlwt,它是pyExcelerator的一个分支,具有错误修复和许多增强功能.从xlwt中消除了pyExcelerator的(非常基本的)xls读取能力.要读取xls文件,请使用xlrd.
如果加载100MB xls文件需要20分钟,则必须使用以下一个或多个:慢速计算机,可用内存极少的计算机或旧版本的Python.
pyExcelerator和xlrd都不读取受密码保护的文件.
免责声明:我是xlrd的作者和xlwt的维护者.