I have a data frame as shown below. which is a sales data of two health care product starting from December 2016 to November 2018.
product profit bougt_date discount
A 50 2016-12-01 5
A 50 2017-01-03 4
B 200 2016-12-24 10
A 50 2017-01-18 3
B 200 2017-01-28 15
A 50 2017-01-18 6
B 200 2017-01-28 20
A 50 2017-04-18 6
B 200 2017-12-08 25
A 50 2017-11-18 6
B 200 2017-08-21 20
B 200 2017-12-28 30
A 50 2018-03-18 10
B 300 2018-06-08 45
B 300 2018-09-20 50
A 50 2018-11-18 8
B 300 2018-11-28 35
Since it is a 3 years data. I would like to create a new column called year_category based on the following criteria.
if bougt_date is from December 2016 to November 2017 both including. then year_category = 2017.
if bought_date is from December 2017 to November 2018, then year_category = 2018
if bought_date is from December 2018 to November 2019, then year_category = 2019
Expected Output:
product profit bougt_date discount year_category
A 50 2016-12-01 5 2017
A 50 2017-01-03 4 2017
B 200 2016-12-24 10 2017
A 50 2017-01-18 3 2017
B 200 2017-01-28 15 2017
A 50 2017-01-18 6 2017
B 200 2017-01-28 20 2017
A 50 2017-04-18 6 2017
B 200 2017-12-08 25 2018
A 50 2017-11-18 6 2017
B 200 2017-08-21 20 2017
B 200 2017-12-28 30 2018
A 50 2018-03-18 10 2018
B 300 2018-06-08 45 2018
B 300 2018-09-20 50 2018
A 50 2018-11-18 8 2018
B 300 2018-11-28 35 2018