Alexis G Alexis G - 3 months ago 13
Python Question

Sampling a datetime from lines for days and columns for hours

I have a matrix where lines represent days and columns represent hours. I am looking for resampling this data to have a datetime as index.

DATES; H0;H1;H2;H3;...
01/01/2013;...;...;...;...;...
02/01/2013;...;...;...;...;...


When I use the df.resample('H') function I get the following results. I want now match the columns value with the hours of each day to fill the values.

2013-01-01 00:00:00 1.35882
2013-01-01 01:00:00 NaN
2013-01-01 02:00:00 NaN
2013-01-01 03:00:00 NaN
2013-01-01 04:00:00 NaN


Does anyone please have an idea on how to proceed?

Thanks Alexis

Answer

Assuming DATES is your index, this should work

df.stack()

If 'DATES' is not your index, you can set it this way

df.set_index('DATES').stack()

Note: This will not set time format to what is in your example

Comments