1

I have a dataset with meteorological features for 2019, to which I want to join two columns of power consumption datasets for 2017, 2018. I want to match them by hour, day and month, but the data belongs to different years. How can I do that?

Power consumption dataset

The meteo dataset is a 6 column similar dataframe with datetimeindexes belonging to 2019.

1 Answers1

0

You can from the index 3 additional columns that represent the hour, day and month and use them for a later join. DatetimeIndex has attribtues for different parts of the timestamp:

import pandas as pd

ind = pd.date_range(start='2020-01-01', end='2020-01-20', periods=10)
df = pd.DataFrame({'number' : range(10)}, index = ind)

df['hour'] = df.index.hour
df['day'] = df.index.day
df['month'] = df.index.month
print(df)

                     number  hour  day  month
2020-01-01 00:00:00       0     0    1      1
2020-01-03 02:40:00       1     2    3      1
2020-01-05 05:20:00       2     5    5      1
2020-01-07 08:00:00       3     8    7      1
2020-01-09 10:40:00       4    10    9      1
2020-01-11 13:20:00       5    13   11      1
2020-01-13 16:00:00       6    16   13      1
2020-01-15 18:40:00       7    18   15      1
2020-01-17 21:20:00       8    21   17      1
2020-01-20 00:00:00       9     0   20      1
lirand
  • 55
  • 1
  • 8