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

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.

Reply
BharathS1307
New Member

Python visual showing error - single positional indexer is out of bounds

I am facing this error in Power BI after changing the datasource of the tables used in the visuals. the table which if feeded to this visuals have data but I am facing this error. 

2 ACCEPTED SOLUTIONS
Ritaf1983
Super User
Super User

Hi @BharathS1307 

This error usually happens when the Python script in Power BI tries to access a row or column that does not exist. Possible causes and solutions:

  1. No data is being passed to the Python visual.
    Even if the source table has data, Power BI filters may be removing all rows before they reach the Python script. Try adding a regular table visual with the same filters to check if any data is available.

  2. The column names or structure have changed.
    If you modified the data source, column names or order might have changed. To debug, add this line inside your script:
    print(df.head())

  3. The script is trying to access a row that does not exist.
    If the script includes df.iloc[0] but the table is empty, this will cause the error. Add a check before accessing rows:
    if not df.empty:
    first_row = df.iloc[0]
    else:
    print("No data available")

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

View solution in original post

rohit1991
Super User
Super User

Hi @BharathS1307 

This error occurs when Python tries to access an index that does not exist after changing the data source. Try these fixes:

1️⃣ Check Data Frame Shape
Add this line at the start of your script to debug:

print(df.shape)  # Check if the dataframe has rows
print(df.head())  # View first few rows
  • If (0, X), your table is empty after transformation.

2️⃣ Check Column Names

  • Ensure column names in the script match the new data source.
  • print(df.columns)  # Check available columns
    

3️⃣ Handle Index Errors Safely
Modify your script to prevent indexing errors:

if not df.empty:
    value = df.iloc[0, 0]  # Adjust index based on data
else:
    value = "No Data"

4️⃣ Refresh Data & Check M Query

  • Manually refresh the dataset in Power BI.
  • Verify the Power Query Editor to ensure data is loading correctly.

Did it work? ✔ Give a Kudo • Mark as Solution – help others too!

View solution in original post

2 REPLIES 2
rohit1991
Super User
Super User

Hi @BharathS1307 

This error occurs when Python tries to access an index that does not exist after changing the data source. Try these fixes:

1️⃣ Check Data Frame Shape
Add this line at the start of your script to debug:

print(df.shape)  # Check if the dataframe has rows
print(df.head())  # View first few rows
  • If (0, X), your table is empty after transformation.

2️⃣ Check Column Names

  • Ensure column names in the script match the new data source.
  • print(df.columns)  # Check available columns
    

3️⃣ Handle Index Errors Safely
Modify your script to prevent indexing errors:

if not df.empty:
    value = df.iloc[0, 0]  # Adjust index based on data
else:
    value = "No Data"

4️⃣ Refresh Data & Check M Query

  • Manually refresh the dataset in Power BI.
  • Verify the Power Query Editor to ensure data is loading correctly.

Did it work? ✔ Give a Kudo • Mark as Solution – help others too!
Ritaf1983
Super User
Super User

Hi @BharathS1307 

This error usually happens when the Python script in Power BI tries to access a row or column that does not exist. Possible causes and solutions:

  1. No data is being passed to the Python visual.
    Even if the source table has data, Power BI filters may be removing all rows before they reach the Python script. Try adding a regular table visual with the same filters to check if any data is available.

  2. The column names or structure have changed.
    If you modified the data source, column names or order might have changed. To debug, add this line inside your script:
    print(df.head())

  3. The script is trying to access a row that does not exist.
    If the script includes df.iloc[0] but the table is empty, this will cause the error. Add a check before accessing rows:
    if not df.empty:
    first_row = df.iloc[0]
    else:
    print("No data available")

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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.