Forum Discussion

ahmedidris's avatar
ahmedidris
Frequent Visitor
6 years ago
Solved

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?

6 Replies

    • dishant92's avatar
      dishant92
      New Member

      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's avatar
        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.    

  • Anonymous's avatar
    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
  • 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