05-06-2024 11:33 PM - edited 05-06-2024 11:46 PM
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')"
05-07-2024 01:46 AM
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! 😊
05-07-2024 03:04 AM
Thanks @Kaniz_Fatma for your reply, Unfortunately I used path as variable in my code but again showing same error. PFB in screenshot.
05-07-2024 04:05 AM
Hi @MohammadWasi,
05-07-2024 04:14 AM
I am using '.xls' format only.
05-07-2024 04:17 AM
Hi @MohammadWasi, Please use ".xlsx".
05-07-2024 04:30 AM
Hi @Kaniz_Fatma I changed file in .xlsx format but again got the same error as above.
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.
If there isn’t a group near you, start one and help create a community that brings people together.
Request a New Group