简体   繁体   English

如何从 python 读取多张 excel 文件? 我收到错误消息说“pandas”没有属性“excel”

[英]How to read excel file with multiple sheets from python? I got error saying 'pandas' has no attribute 'excel'

At first, I wrote:一开始,我写道:

import numpy as np
import pandas as pd
import glob
all_data = pd.DataFrame()
for f in glob.glob("*.xlsx"):
    df = pd.read_excel(f)
    all_data = all_data.append(df, ignore_index=True)

now save the data frame现在保存数据框

Covid_Apr2022_data = pd.excel('Covid-19 April to May 2022 data only.xlsx')
all_data.to_excel(Covid_Apr2022_data)
Covid_Apr2022_data.save() 

sheet1 = xls.parse(0)

I got the error message:我收到错误消息:

AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_33/1438062488.py in <module>
      8 
      9 # now save the data frame
---> 10 Covid_Apr2022_data = pd.excel('Covid-19 April to May 2022 data only.xlsx')
     11 all_data.to_excel(Covid_Apr2022_data)
     12 Covid_Apr2022_data.save()

/opt/conda/lib/python3.7/site-packages/pandas/__init__.py in __getattr__(name)
    242         return _SparseArray
    243 
--> 244     raise AttributeError(f"module 'pandas' has no attribute '{name}'")
    245 
    246 

AttributeError: module 'pandas' has no attribute 'excel'

I also gave another attempt:我还进行了另一种尝试:

import pandas as pd

df = pd.read_excel('../input/covid19-april-2022-data/Covid-19 April to May 2022 data only.xlsx', sheet_name = None)

But got this ImportError:但是得到了这个 ImportError:

Missing optional dependency 'openpyxl'.  Use pip or conda to install openpyxl.

Then I install 'openpyxl', but it can't recognize it as the module.然后我安装'openpyxl',但它无法将其识别为模块。

Check for the environment in which you're installing openpyxl检查安装 openpyxl 的环境

source <env_name>/bin/activate
pip install openpyxl

or maybe try installing using conda:或者尝试使用 conda 安装:

conda install -n <env_name> openpyxl

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 Python/Pandas 创建具有多张工作表的 Excel 文件 - Create an Excel file with multiple sheets with Python/Pandas 如何让python一张一张地读取一个excel文件上的多张纸 - How to make python read multiple sheets on an excel file one by one 如何使用pandas read_excel多处理多个excel表? - How to multiprocess multiple excel sheets using pandas read_excel? 如何通过pandas将多个工作表中的列合并到一个excel文件中 - How to merge columns from multiple sheets in one excel file by pandas 如何在 pandas 中打开一个 excel 文件? - How to open an excel file with multiple sheets in pandas? 如何将熊猫read_excel()用于多张Excel文件? - How to use pandas read_excel() for excel file with multi sheets? Python:如何将多个 Excel 工作表读取到列表中? - Python: How to read multiple Excel sheets into a list? 如何将数据从多个工作表的一个Excel文件复制到多个工作表的另一个Excel文件中 - How do I copy the data from one Excel file of multiple sheets to another Excel file of multiple sheets 如何使用 python 中的 for 循环读取 excel 文件中的工作表 - how to read sheets in an excel file with a for loop in python 如何使用 Python 3 和 Pandas 从多个 Excel 工作表中提取相同的行号并将其放在一起? - How can I use Python 3 and pandas to extract and put together same row numbers from multiple excel sheets?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM