1

Coming from a MultiIndex:

multiindex_time_index

I can select the TimeIndex using get_level_values

hist_vol_to_display.index.get_level_values('ts_timeonly')

pandas dataframe timeindex to be converted to DateTimeIndex

So all of the rows have happend on a specific date (e.g. 2019-09-16).

What is an efficient way to replace the TimeIndex with a DateTimeIndex?

Can I replace the Index inplace or do I need to work around this using a new column? Thanks!

gies0r
  • 4,723
  • 4
  • 39
  • 50

1 Answers1

1

You can use MultiIndex.set_levels:

x  = pd.to_datetime('2019-09-16 ' + hist_vol_to_display.index.levels[1].astype(str))
hist_vol_to_display.index = hist_vol_to_display.index.set_levels(x, level=1)
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252