How to remove day from datetime index in pandas?

The idea behind this question is that when I work with full datetime tags and data from different days, I sometimes want to compare how the hourly behavior compares. But since the days are different, I can’t directly build two data sets in 1 hour on top of each other.

My naive idea would be that I need to remove the day from the datetime index on both sets, and then build them on top of each other. What is the best way to do this?

Or alternatively, what's the best approach to my problem?

+4
source share
1 answer

This may not be exactly the same, but should help you, assuming ts is your time:

 hourly = ts.resample('H') hourly.index = pd.MultiIndex.from_arrays([hourly.index.hour, hourly.index.normalize()]) hourly.unstack().plot() 

If you don't need AT ALL day, just hourly.index = hourly.index.hour should work

+3
source

All Articles