set value to 99 percentile for each column in a dataframe <p>I am working with the data which looks like a dataframe described by</p> <pre><code>df = pd.DataFrame({'AAA' : [1,1,1,2,2,2,3,3], 'BBB' : [2,1,3,4,6,1,2,3]}) </code></pre> <p>what i would like to do is to set value to roundup(90%) if value exceeds 90 percentile. So its like capping max to 90 percentile. This is getting trickier for me as every column is going to have different percentile value.</p> <p>I am able to get 90 percentile value using</p> <pre><code>df.describe(percentiles=[.9]) </code></pre> <p>so for column BBB 6 is greater than 4.60 (90 percentile), hence it needs to be changed to 5 (roundup 4.60).</p> <p>In actual problem I am doing this for large matrix, so I would like to know if there is any simple solution to this, rather than creating an array of 90 percentile of columns first and then checking elements in for a column and setting those to roundup of 90 percentile</p>