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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
ahmedidris
Frequent Visitor

Python script error:"the preview for section 1/query1/source doesn't exist"

Hi,

When I tryto run this simple python script in power bi it throws this error " the preview for section 1/query1/source doesn't exist"

 

import pandas as pd
data = [['Alex',10],['Bob',12],['Clarke',13]]
df = pd.DataFrame(data,columns=['Name','Age'],dtype=float)
print (df)

How to fix this?
1 ACCEPTED SOLUTION
Pragati11
Super User
Super User

Hi @ahmedidris ,

 

I am asssuming that you are following the below link to run this pythin script:

https://docs.microsoft.com/en-us/power-bi/connect-data/desktop-python-scripts

 

I tried doing same and I can successfully run the script in python editor:

pythont.png

 

Also, make sure your Python home directory path is defined correctly in Power BI Desktop:

Pragati11_0-1596805659191.png

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

View solution in original post

6 REPLIES 6
Quentin
Helper IV
Helper IV

Hello everyone, Have you managed to solve your issue? 

I face exactly the same error message "the preview for section 1/query1/source doesn't exist" when using a R script:

R script works in RStudio and other Rscript works in the same pbix (therefore link to R work well).

 

Here is the R script reading from Humanitarian Data Exchange package rhdx:

 

library(rhdx)
library(tidyverse)
library(stringr)
library(dplyr)

dataset<-search_datasets("INFORM Country Risk Profiles", rows = 3)
ds<-get_resources(nth(dataset,1))
nb_ds<-length(ds)


Hazards<- vector("list", length = nb_ds)
var_interes<-c("COUNTRY","Iso3","Physical exposure to earthquake","Physical exposure to flood","Physical exposure to tsunami","Physical exposure to tropical cyclone","Droughts probability and historical impact","Physical exposure to epidemics","INFORM Natural Hazard","GCRI Internal Conflict Score","Current Highly Violent Conflict Intensity Score","INFORM Human Hazard")

for (i in 1:nb_ds){
Hazards[[i]]=read_resource(ds[i][[1]],sheet="Hazard & Exposure")
for (j in names(Hazards[[i]])){
if (!(j %in% var_interes)){
Hazards[[i]]<-Hazards[[i]][-c(which( colnames(Hazards[[i]])==j ))]
}
}
Hazards[[i]]$name_ds<-ds[i][[1]][["data"]][["name"]]
Hazards[[i]]$desc_ds<-ds[i][[1]][["data"]][["description"]]
Hazards[[i]]$format_ds<-ds[i][[1]][["data"]][["format"]]
Hazards[[i]]$Index<-i
}

INFORM_RISK_Hazard<-do.call(bind_rows,Hazards)
INFORM_RISK_Hazard

 

Anonymous
Not applicable

Hi @ahmedidris ,

 

Can you show the M code?

I tried blank query, it worked well

 

let
    Source = Python.Execute("import pandas as pd#(cr)#(lf)data = [['Alex',10],['Bob',12],['Clarke',13]]#(cr)#(lf)df = pd.DataFrame(data,columns=['Name','Age'],dtype=float)#(cr)#(lf)print (df)")
in
    Source
Pragati11
Super User
Super User

Hi @ahmedidris ,

 

I am asssuming that you are following the below link to run this pythin script:

https://docs.microsoft.com/en-us/power-bi/connect-data/desktop-python-scripts

 

I tried doing same and I can successfully run the script in python editor:

pythont.png

 

Also, make sure your Python home directory path is defined correctly in Power BI Desktop:

Pragati11_0-1596805659191.png

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Hi Pragati,

 

I tried the steps mentioned by you but still I am getting the same error. Is there anything else which needs to be done

Anonymous
Not applicable

Hi, I also faced this error when trying to connect my python script to power bi, while the python script works well by itself. I fixed the connection error by simplifying my script, e.g. reducing the number of function within a function, avoiding complex calculations.  I just keep trial and error until my script is 'simple' enough for power bi to process it.    

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.