I wanted to clip values of a DataFrame into their inter qantile range, so that:
- If the actual value is higher than its 75th percentile it will default to 75th percentile value
- If the actual value is lower than 25th percentile it will default to 25th percentile.
- If the value is in between 25th and 75th percentile it will be the same value.
Is there a way to do it for all columns in one go (i.e. A max becomes 3, B and C max become 2.25)
test = pd.DataFrame({'A':[1,2,3,1,2,3,1,1,2,3,1,12],
'B':[0,1,2,1,0,1,3,1,2,1,3,9],
'C':[0,1,2,2,1,2,3,1,2,1,4,17]})
test.describe()
A B C
25% 1.000000 1.000000 1.000000
75% 3.000000 2.250000 2.250000
max 12.000000 9.000000 17.000000