首页 > 解决方案 > 如何处理 book.parse(sheet) 上的内存错误

问题描述

在 book.parse(sheet) 上出现内存错误

读取目录中的一些文件后出现内存错误book.parse(sheet)

for filename in os.listdir(cwd):
        if filename.endswith('.xlsx') and not filename.startswith(('1Data')):
            book = pd.ExcelFile(filename)
            print(filename)
            for sheet in book.sheet_names:
                df = book.parse(sheet) #how can i handle this 
                if 'comp' in df.columns:
                    df['comp1']=df['comp']
                    print("For "+filename+"\n")
                    book2=df.pivot_table(values='comp1',index=['pe','id'], columns='comp', aggfunc='count',margins=True)
               

标签: python-3.xpandasopenpyxl

解决方案


推荐阅读