I have a csv like this:
date,asin,ordered,forecast
2020-05-31,AAAAAA,300,1000
2020-05-31,BBBBBB,500,2000
...
2020-06-28,AAAAAA,980,1500
2020-06-28,BBBBBB,1900,2500
I want to find the date
+ 28 days and add a new column with the value in ordered. For example, adding 28 days to 2020-05-31
will give me 2020-06-28
. For date = 2020-05-31
and asin = AAAAAA
, there will be a new column new
with the number 980
(from ordered
column), which corresponds to the same asin
but different date (2020-06-28
):
date,asin,ordered,forecast,new
2020-05-31,AAAAAA,300,1000,980
2020-05-31,BBBBBB,500,2000,1900
...
2020-06-28,AAAAAA,980,1500, <this value will look for the date 28 days after 2020-06-28 and asin AAAAAA and get that ordered value>
2020-06-28,BBBBBB,1900,2500 <this value will look for the date 28 days after 2020-06-28 and asin BBBBBB and get that ordered value>
So far I have gotten the +28 days part by doing df['date'] + pd.DateOffset(days=28)
but I don't know how to search for the new date and asin elsewhere in the dataframe and bring in the ordered value to the current row.
2020-05-31,BBBBBB
row? Shouldn't be ` NaN` (once you're specified to use onlyasin = AAAAAA
)? – Cainã Max Couto-Silva Dec 3 '20 at 23:31asin=BBBBBB
indate=2020-06-28
because it needs to match theasin
as well as date+28days – kindofhungry Dec 3 '20 at 23:36