Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

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 B...
  • v-yuta-msft's avatar
    v-yuta-msft
    7 years ago

    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

     

     

    After expand, the result is like this:

     

     

    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.