'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:

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

Then I install 'openpyxl', but it can't recognize it as the module.



Solution 1:[1]

Check for the environment in which you're installing openpyxl

source <env_name>/bin/activate
pip install openpyxl

or maybe try installing using conda:

conda install -n <env_name> openpyxl

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rahul Agarwal