import pandas as pd
import glob
location = ‘C:\Users\oliver.r.caluag\Desktop\sample merge\merged file\*.xlsx’
excel_files = glob.glob(location)
pd.set_option(‘display.max_rows’, 91)
pd.set_option(‘display.max_columns’,9)
df1 = pd.DataFrame()
for excel_file in excel_files:
df2 = pd.read_excel(excel_file)
df1 = pd.concat([df1, df2], ignore_index=True)
df1.fillna(value=“N/A”, inplace=True)
df1.to_excel(‘C:\Users\oliver.r.caluag\Desktop\sample merge\merged file\all_sleep_data.xlsx’)
print(df1)
Error received:
C:\Users\oliver.r.caluag\PycharmProjects\pythonProject\venv\Scripts\python.exe “C:/Users/oliver.r.caluag/Desktop/python excel/all_sleep_data.py”
Traceback (most recent call last):
File “C:\Users\oliver.r.caluag\Desktop\python excel\all_sleep_data.py”, line 15, in
df2 = pd.read_excel(excel_file)
File “C:\Users\oliver.r.caluag\PycharmProjects\pythonProject\venv\lib\site-packages\pandas\util_decorators.py”, line 311, in wrapper
return func(*args, **kwargs)
File “C:\Users\oliver.r.caluag\PycharmProjects\pythonProject\venv\lib\site-packages\pandas\io\excel_base.py”, line 364, in read_excel
io = ExcelFile(io, storage_options=storage_options, engine=engine)
File “C:\Users\oliver.r.caluag\PycharmProjects\pythonProject\venv\lib\site-packages\pandas\io\excel_base.py”, line 1233, in init
self._reader = self._engines[engine](self._io, storage_options=storage_options)
File “C:\Users\oliver.r.caluag\PycharmProjects\pythonProject\venv\lib\site-packages\pandas\io\excel_openpyxl.py”, line 521, in init
import_optional_dependency(“openpyxl”)
File “C:\Users\oliver.r.caluag\PycharmProjects\pythonProject\venv\lib\site-packages\pandas\compat_optional.py”, line 118, in import_optional_dependency
raise ImportError(msg) from None
ImportError: Missing optional dependency ‘openpyxl’. Use pip or conda to install openpyxl.
Process finished with exit code 1
Why I am still receiving these errors, I installed openpyxl using pip install openpyxl and tested it fine?
Test for openpyxl:
Python 3.9.5 (tags/v3.9.5:0a7dcbd, May 3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
import openpyxl