3 weeks ago - last edited 3 weeks ago
I can list out the file using dbutils but can not able to read files in databricks. PFB in screenshot. I can able to see the file using dbutils.fs.ls but when i try to read this file using read_excel then it is showing me an error like "FileNotFoundError: [Errno 2] No such file or directory: '/FileStore/xxx/abcd.xls'". I used to read excel file as
"df_mem = pd.read_excel('/FileStore/xxx/abcd.xls', engine='openpyxl', sheet_name = 'Sheet 1')"
3 weeks ago
Hi @MohammadWasi, It seems like youโre encountering a common issue related to file paths when working with pd.read_excel
in Python.
Letโs troubleshoot this step by step:
Check the File Path:
abcd.xls
) is indeed located in the specified directory (/FileStore/xxx/
).Use Absolute Paths:
os
module in Python. Hereโs an example:
import os
pre = os.path.dirname(os.path.realpath(__file__))
fname = 'abcd.xls'
path = os.path.join(pre, fname)
df_mem = pd.read_excel(path, engine='openpyxl', sheet_name='Sheet 1')
Convert to CSV (Optional):
abcd.xls
) to a CSV file.pd.read_csv
:
df_mem = pd.read_csv('path/to/abcd.csv')
Remember to replace 'path/to/abcd.csv'
with the actual path to your CSV file if you choose this option. Hopefully, one of these steps will resolve the issue! ๐
3 weeks ago
Thanks @Kaniz for your reply, Unfortunately I used path as variable in my code but again showing same error. PFB in screenshot.
3 weeks ago
Hi @MohammadWasi,
3 weeks ago
I am using '.xls' format only.
3 weeks ago
Hi @MohammadWasi, Please use ".xlsx".
3 weeks ago
Hi @Kaniz I changed file in .xlsx format but again got the same error as above.