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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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

3 REPLIES 3
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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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