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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. 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 III
Helper III

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

 

Vera_33
Resident Rockstar
Resident Rockstar

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

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
March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.