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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Python: DateTimeIndex not showing in PowerBI

Hi, my code runs smoothly in Spyder, so I don't think it's an issue with my code.

 

However, most of my variables are dataframes, and when I copy the whole code over to the Python Script in Power BI and try to run it, my DatetimeIndex in all my dataframes are no longer shown in the preview, instead it just shows an integer index starting from 1. As a result, when I try to plot my results, it ends up only having one column of data and I can't plot a line graph.

1 ACCEPTED SOLUTION

@Anonymous,

 

I can reproduce your issue, just add a statement in the button of your code like pattern below:

# 'dataset' holds the input data for this script
import datetime
import pandas as pd
import numpy as np

def datetimeix(df):
    df['Date\t'] = pd.DatetimeIndex(df['Date\t'])
    df.set_index('Date\t', inplace = True)
    return df

df = pd.read_csv(r'C:\Users\JimmyTao\Desktop\Test.csv') 

dataset = df

Capture.PNG 

 

After expand, the result is like this:

2.PNG 

 

Community Support Team _ Jimmy Tao

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

4 REPLIES 4
HALI322
New Member

I got similar issue in getting data from a API datasource (Wind Financial System-A Chinese financial terminal like Bloomberg). Python script code is as follow:

 

import pandas as pd
from WindPy import *
w.start()

Wind_Data = w.edb("M0039354", "2000-01-01", "2024-11-11","Fill=Previous")
GDP = pd.DataFrame(Wind_Data.Data, columns=Wind_Data.Times, index=Wind_Data.Fields).T
GDP

 

In Python window, it did feedback transposed dataset include a date index and a column of GDP data. But in Power BI, the return left only GDP data column. The date index column disappeared. Python command line running result below:

>>> import pandas as pd
>>> from WindPy import *
>>> w.start()
.ErrorCode=0
.Data=[Already connected!]
>>>
>>> Wind_Data = w.edb("M0039354", "2000-01-01", "2024-11-11","Fill=Previous")
>>> GDP = pd.DataFrame(Wind_Data.Data, columns=Wind_Data.Times, index=Wind_Data.Fields).T
>>> GDP
                CLOSE
2000-03-31 8.7
2000-06-30 9.1
2000-09-30 8.8
2000-12-31 7.5
2001-03-31 9.5
... ...
2023-09-30 4.9
2023-12-31 5.2
2024-03-31 5.3
2024-06-30 4.7
2024-09-30 4.6

[99 rows x 1 columns]
>>>

Someone help?

(don't worry, all data included are publicly available China GDP growth rate data. No sensitive/private information included.)

v-yuta-msft
Community Support
Community Support

@Anonymous,

 

Could share some part of the code? Basically, the interaction between python and power bi should be like pattern below:

 

#dataset present the current table in power bi as input
#dataset = pd.DataFrame(data, index, columns, dtype, copy)
import pandas as pd

completedData = dataset.fillna(method = 'backfill', inplace = False)
dataset["completedValues"] = completedData[SMI missing values"] #Modify a column


Regards,

Jimmy Tao

Anonymous
Not applicable

Hi, part of the code is shown below:

 

import datetime
import pandas as pd
import numpy as np
import statsmodels.api as sm



def datetimeix(df):
df['Date'] = pd.DatetimeIndex(df['Date'])
df.set_index('Date', inplace = True)
return(df)



df = pd.read_csv(r'C:\Users\blai\Documents\5 year dataset.csv', encoding = "ISO-8859-1") 

mthnsr = cumtotal(df) 

mthnsr = datetimeix(mthnsr)

 

@Anonymous,

 

I can reproduce your issue, just add a statement in the button of your code like pattern below:

# 'dataset' holds the input data for this script
import datetime
import pandas as pd
import numpy as np

def datetimeix(df):
    df['Date\t'] = pd.DatetimeIndex(df['Date\t'])
    df.set_index('Date\t', inplace = True)
    return df

df = pd.read_csv(r'C:\Users\JimmyTao\Desktop\Test.csv') 

dataset = df

Capture.PNG 

 

After expand, the result is like this:

2.PNG 

 

Community Support Team _ Jimmy Tao

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

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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