Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
I had connected Anaconda to use Python in Power BI. When I attached the data and added the code, it showed me an error.
DataSource.Error: ADO.NET: Python script error.
<pi>FileNotFoundError: [Errno 2] No such file or directory: 'Clean sales data by store 3.0.csv'
</pi>
Details:
DataSourceKind=Python
DataSourcePath=Python
Message=Python script error.
<pi>FileNotFoundError: [Errno 2] No such file or directory: 'Clean sales data by store 3.0.csv'
</pi>
ErrorCode=-2147467259
Do someone know why that happen? I have been looking in different blogs about it, but I have not idea if I should change this code I have used:
# Load your dataset into a DataFrame
df = pd.read_csv('Clean sales data by store 3.0.csv', delimiter=';')
For the actual address where the file host in my computer...
I am curious to know how it works.
Cheers.
Thank you Ritaf1983
Hi, @byh1154
Depending on the error you are proposing, make sure you enter the correct path, if you say the wrong path, you will run into the current problem:
import pandas as pd
df = pd.read_csv('sales1.csv', delimiter=',')
To solve this problem, first I found this csv file path in my computer:
Then I successfully imported the data using the following python code:
import pandas as pd
df = pd.read_csv('C:\\Users\\xxxx\\Desktop\\sales.csv', delimiter=',')
Best Regards
Jianpeng Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @byh1154
The error you're encountering in Power BI when using Python is related to the path specified in your script. The `FileNotFoundError` suggests that Python can't find the file `Clean sales data by store 3.0.csv` at the path you've specified. Here’s a breakdown of how to address this issue and understand how Power BI integrates with Python:
### Understanding the Error
1. **FileNotFoundError**: This error indicates that the file you're trying to read does not exist at the specified location. This could be due to an incorrect file path or the file not being in the expected directory.
2. **Python and Power BI Integration**: When you use Python scripts in Power BI, the Python environment runs the script. However, the context in which the script runs might not be the same as your local environment. Power BI doesn’t inherently know the local paths on your machine.
### Troubleshooting Steps
1. **Check File Path**:
- **Absolute Path**: Ensure you use the absolute path to the file. For example, if your file is located at `C:\Data\Clean sales data by store 3.0.csv`, you should specify this exact path in your script.
```python
df = pd.read_csv(r'C:\Data\Clean sales data by store 3.0.csv', delimiter=';')
```
- **Relative Path**: If you prefer using a relative path, make sure the file is located relative to the working directory of your Python environment.
2. **Verify File Location**:
- Ensure the file `Clean sales data by store 3.0.csv` is actually present at the specified path.
- Double-check the file name for typos or discrepancies in the file extension.
3. **Permissions**:
- Make sure that the Python environment used by Power BI has the necessary permissions to access the file and directory.
4. **Test Outside Power BI**:
- Run the Python script directly in a Python environment (like Anaconda) to verify that it can access the file. This helps isolate whether the issue is with the file path or with the Power BI integration.
5. **Power BI Python Scripting Environment**:
- **Current Directory**: Be aware that Power BI runs Python scripts in its own environment, which might have a different working directory. You might want to set the working directory explicitly in your script.
```python
import os
os.chdir(r'C:\Data') # Set working directory to where the file is located
df = pd.read_csv('Clean sales data by store 3.0.csv', delimiter=';')
```
6. **Using Power BI Parameters**:
- If your file path might change or you want to make it dynamic, consider using Power BI parameters to pass the file path to the Python script.
### Example Python Code for Power BI
Here’s how you might adapt your script to ensure it works correctly within Power BI:
```python
import pandas as pd
import os
# Set the working directory if necessary
# os.chdir(r'C:\Data') # Uncomment and set this if needed
# Load your dataset into a DataFrame
df = pd.read_csv(r'C:\Data\Clean sales data by store 3.0.csv', delimiter=';')
# Ensure that the DataFrame is returned as output
df
```
### Conclusion
In summary, ensure that you are using the correct and absolute path to the file in your Python script and that the file exists at that location. Also, consider setting the working directory explicitly if needed. Testing your script outside Power BI can help confirm if the issue is with the file path or the Power BI environment setup.
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 40 | |
| 35 | |
| 34 | |
| 31 | |
| 27 |
| User | Count |
|---|---|
| 135 | |
| 102 | |
| 67 | |
| 65 | |
| 56 |