I'd like to add supplementary information from df2 to df1 by matching date data.
df1 is the main dataframe:
x0 x1 x2 x3 x4 x5 ... x10000 Date
1 40 31.05 25.5 25.5 25.5 25 ... 33 2013-11-13
2 35 35.75 36.5 36.5 36.5 36.5 ... 29 2013-09-05
⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮
df2 is the supplementary weather info I want to add to df1:
year month day maxtemp mintemp rainfall wind
2013 1 1 26.2 20.2 0 32.4
2013 1 2 22.9 20.3 0 10
2013 1 3 24.8 18.4 0 28.8
2013 1 4 26.6 18.3 0 33.5
2013 1 5 28.3 20.9 0 33.4
2013 1 6 28 21.6 0 32.8
2013 1 7 27.5 21.4 0 26.8
2013 1 8 42.3 20.9 0 25.5
2013 1 9 25 21.1 0 20.9
2013 1 10 25.4 20.2 0 14
⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮
I need to add preceding 100 days of maxtemp
,mintemp
,rainfall
and wind
data extracted from df2
, to the end of the each row on df1 horizontally, by matching with year
, month
, day
of Date
in df1
. So Date
is the 100th day and the previous 99 days are the 99 days before Date
.
Expected output:
x0 x1 x2 x3 x4 x5 ... x10000 Date max_t1...max_t100 min_t1...min_t100 rf1... rf100 w1 ... w100
1 40 31.05 25.5 25.5 25.5 25 ... 33 2013-01-01 26.2 ... 20.2 ... 0 ... 32.4...
2 35 35.75 36.5 36.5 36.5 36.5 ... 29 2013-01-03 24.8. ... 18.4 ... 0 ... 28.8
⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮ ⋮
where
max_t1, ..., max_t100 represent max temperature from day1 to day100(`Date` day);
min_t1, ..., min_t100 represent min temperature from day1 to day100(`Date` day);
rf1, ..., rf100 represent rainfall from day1 to day100(`Date` day);
w1, ..., w100 represent wind from day1 to day100(`Date` day).
these are the newly added column names(so there will be 400 new columns in total).