Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
byh1154
New Member

Error: ADO.NET: Python script error 2.

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.

2 REPLIES 2
Anonymous
Not applicable

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=',')

vjianpengmsft_1-1725348287617.png

vjianpengmsft_2-1725348319667.png

To solve this problem, first I found this csv file path in my computer:

vjianpengmsft_3-1725348406387.png

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=',')

vjianpengmsft_4-1725348540326.png

vjianpengmsft_5-1725348565345.png

vjianpengmsft_6-1725348592888.png

 

 

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.

Ritaf1983
Super User
Super User

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.