I have a numeric column in a dataframe from which I need to categorize that row based on it's value. For example,
id value
1 2.0
2 3.0
3 4.5
4 5.5
I need a new category variable group
based on the quantile value of the rows that have come before that row. So, for id=2
, it will consider rows 1 and 2 in the quantile calculation. And then do the categorization like:
if value > quantile(90%) category = 'Very High'
if value > quantile(75%) & value <= quantile(90%) & category = 'High'
if value > quantile(25%) & value <= quantile(75%) & category = 'Normal'
if value <= quantile(25%) category = 'Low'
How would I calculate the quantile like that and do the comparison?