Forum Discussion
Syndicate_Admin
Administrator
2 years agoPROBLEMA SCRIPT PYTHON AND POWERBI
Good afternoon, I'm trying to launch a forecast script inside PowerBi, specifically this one: import pandas as pd
import statsmodels.api as sm
data = PerfilCliente[['FECHA', ...
Anonymous
2 years agoNot applicable
Hi, Syndicate_Admin
Make sure that PerfilCliente has been properly imported into the Python script. In Power BI, you need to use the pandas gallery to read datasets from Power BI's data model. You can do this by using the dataset variable provided by Power BI.
You can also refer to the code below:
import pandas as pd
import statsmodels.api as sm
# Import the dataset from Power BI
PerfilCliente = dataset
# Ensure the columns are correctly referenced
data = PerfilCliente[['FECHA', 'PESO']]
data['FECHA'] = pd.to_datetime(data['FECHA'])
data.set_index('FECHA', inplace=True)
data = data.sort_index()
data_diff = data.diff().dropna()
model = sm.tsa.ARIMA(data_diff, order=(1, 1, 1))
model_fit = model.fit()
forecast = model_fit.forecast(steps=90)
forecast_dates = pd.date_range(data.index[-1], periods=90, freq='D')
forecast_df = pd.DataFrame(forecast, index=forecast_dates, columns=['Predicción_Peso'])
forecast_df.reset_index(inplace=True)
forecast_df.rename(columns={'index': 'FECHA'}, inplace=True)
forecast_df['FECHA'] = forecast_df['FECHA'].dt.strftime('%Y-%m-%d')
result = forecast_df
How to Get Your Question Answered Quickly
Best Regards
Yongkang Hua
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.