Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more
PYTHON INTEGRATION WITH POWER BI
IMPORTING EXCEL TO POWER BI, DATA CLEANING AND CREATING VISUALS
We all know that Python is a programming language widely used by statisticians, data scientists, and data analysts. It’s great news that it has been integrated into Power BI Desktop in Power BI Desktop August 2018 Feature Release. Once we enable the feature and install python, we can use Python script to import data source, cleaning the data, analysing the same and creating visualization with that.
Importing Excel to Power BI using Python script
Fig 1
Fig 2
py -m pip install pandas
Fig 3
Once I click on OK, it shows the excel data into right side pane. Clicking on Load will load all data into Power BI.
Fig 4
Click on Load, all the data loaded to Power BI using Python script. In Power BI Data tab, we will get the excel data as below. Fig 5
Fig 5
Data Cleaning using Python script
Fig 6
Fig 7
Fig 8
Fig 9
Fig 10
Data Visualization using Python script
Fig 11
Fig 12
Fig 13
Fig 14
py -m pip install matplotlib
Fig 15
Fig 16
Fig 17
Fig 18
Solved! Go to Solution.
Hi @Anonymous ,
Thanks for sharing.
Best Regards,
Jay
Community Support Team _ Jay Wang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thank you so much shared document is very helpful.
Hi ,
How to read sharepoint data into Power BI using Python script?
I tried the most obvoius:
import pandas as pd
df= pd.read_excel(''https://xxx.sharepoint.com/:x:/t/SharepointName /EeHqIAO3Xk9Dj_7rpnzojl4BxoF9zvDF_nyQo9CKizcsCw?e=qHdsmF"='')
I tried
import sharepy s = sharepy.connect("example.sharepoint.com")
r = s.getfile("https://example.sharepoint.com/Library/Test%20File.pdf")
I tried the office365 library
#import all the libraries from office365.runtime.auth.authentication_context import AuthenticationContext from office365.sharepoint.client_context import ClientContext from office365.sharepoint.files.file import File import io import pandas as pd #target url taken from sharepoint and credentials url = 'https://company.sharepoint.com/Shared%20Documents/Folder%20Number1/Folder%20Number2/Folder3/Folder%20Number4/Target_Excel_File_v4.xlsx?cid=_Random_letters_and_numbers-21dbf74c' username = 'Dumby_account@company.com' password = 'Password!' ctx_auth = AuthenticationContext(url) if ctx_auth.acquire_token_for_user(username, password): ctx = ClientContext(url, ctx_auth) web = ctx.web ctx.load(web) ctx.execute_query() print("Authentication successful") response = File.open_binary(ctx, url) #save data to BytesIO stream bytes_file_obj = io.BytesIO() bytes_file_obj.write(response.content) bytes_file_obj.seek(0) #set file object to start #read excel file and each sheet into pandas dataframe df = pd.read_excel(bytes_file_obj, sheetname = None)
In all cases I get an error and it is mainly because it is an organizational account sharepoint, I cannot leave my credentials in there and it is expected that other people can refresh the data model from the workspace using their own credentials.
Is there an easy way to connect to a sharepoint file from power bi using a python code? I need Python because it is the only place I can use regex easily.
Any help is welcome :-)!
Hi @Anonymous ,
Thanks for sharing.
Best Regards,
Jay
Community Support Team _ Jay Wang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Check out the April 2025 Power BI update to learn about new features.
Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.
User | Count |
---|---|
93 | |
58 | |
44 | |
35 | |
34 |