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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
vasimnps
New Member

Connection through python script

Following instructions from here https://docs.microsoft.com/en-us/power-bi/desktop-python-scripts

I can run the following python code and generate data.

 

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

 

 

I contructed same df in a class - created a package named Mypackage

 

import pandas as pd
class Mydata:
    def __init__(self):
    pass

    def main_page(self):
    data = [['Alex',10],['Bob',12],['Clarke',13]]
    df = pd.DataFrame(data,columns=['Name','Age'],dtype=float)
    return df

 

 

Now when I call the data, nothing is returned

 

from Mypackage import MyData
df = Mydata().main_page()
print(df)

 

 

If I try 

 

from Mypackage import MyData
df = Mydata().main_page()
print(df.head())

 

 

 Then I get the following error

 

Unable to connect
Details: "ADO.NET: Python script error.
Traceback (most recent call last):
  File "PythonScriptWrapper.PY", line 13, in <module>
    print(df.head())
AttributeError: 'NoneType' object has no attribute 'head'
"

 

 

 

 

1 ACCEPTED SOLUTION
v-xuding-msft
Community Support
Community Support

Hi @vasimnps ,

What the version of Python do you install? If you use 3.7, please install Python 3.6 to have a try. And make sure you have installed Pandas package.

 

Best Regards,

Xue Ding

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-xuding-msft
Community Support
Community Support

Hi @vasimnps ,

What the version of Python do you install? If you use 3.7, please install Python 3.6 to have a try. And make sure you have installed Pandas package.

 

Best Regards,

Xue Ding

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you very much @v-xuding-msft 

 

V3.6 did the trick, any reason why so?

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

July Power BI Update Carousel

Power BI Monthly Update - July 2026

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

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.

Top Solution Authors