I have a data frame as shown below
df:
product_x year total_price total_sale
A 2016 50 200
B 2016 200 100
A 2017 250 250
B 2017 1000 300
A 2018 100 50
B 2018 900 600
K 2016 20 300
D 2016 100 450
In above data frame I would like add new column called total_sale_Quartile.
Explanation to calculate total_sale_Quartile.
sort total_sale as shown below
50, 100, 200, 250, 300, 300, 450, 600
Q1 = 50 to 100
Q2 = 101 to 250
Q3 = 251 to 300
Q4 = 301 to 600
Expected output:
product_x year total_price total_sale total_sale_Quartile
A 2016 50 200 Q2
B 2016 200 100 Q1
A 2017 250 250 Q2
B 2017 1000 300 Q3
A 2018 100 50 Q1
B 2018 900 600 Q4
K 2016 20 300 Q3
D 2016 100 450 Q4