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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Using Power BI and Python for Data Science - statsmodels.api

Hi all,

 

I'm trying to use Power BI and Python to get a multivariate regression model built in Power BI Desktop. Using Python, I've imported the following packages to get started: pandas, numpy, matplotlib, statsmodels

 

Let's assume two independent variables (X1 and X2) and 1 dependent variable Y. 

 

When using Python, I've used this script:

 

import pandas as pd

import numpy as np

import matplotlib as plt

import statsmodels.api as sm

dataframe = pandas.DataFrame["X1 data", "X2 data", "Y data"]

 

X1 = dataframe["Name of X1 variable"]

X2 = dataframe["Name of X2 variable"]

Y = dataframe["Name of Y variable"]

model = sm.OLS(Y, X)

results = model.fit()

print(results.summary())

 

Which creates the image <here> , but the command doesn't work in Power BI. Does anyone have any ideas? 

3 REPLIES 3
v-kelly-msft
Community Support
Community Support

Hi @Anonymous ,

 

Have you defined values to your variable?What is the error returned?

Here is the reference you can refer to.

 

 

 

Best Regards,
Kelly
 
Did I answer your question? Mark my post as a solution!
amitchandak
Super User
Super User
Greg_Deckler
Community Champion
Community Champion

First thing I would check is if all of those packages are supported in Power BI. Also, define "does not work", do you get an error, blank screen, Power BI crashes and burns?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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