I have imported a timeseries dataset in pandas from a csv file.
data = pd.read_csv('djia_data.csv')
data.set_index('date')
When I print the header withdata.head()
, I correctly get
If instead I visualize the dataframe (double click on the variable in VS code with Jupiter), I get this
I do not understand while I do not get date as the new index anymore. If instead I type
data = pd.read_csv('djia_data.csv')
data.set_index('date',inplace=True)
data.head()
I get this
When I visualize again the dataframe as a variable instead I obtain
In this case, date column is empty. I've searched on the net but I wasn't able to solve it. Can you please explain what I am doing wrong?
CodePudding user response:
Try to set index earlier:
data = pd.read_csv('djia_data.csv', index_col='date', parse_dates=['date'])