1

I have a dataframe which consists of columns of numbers. I am trying to calc the decile rank values for each column. The following code gives me the values for the dataframe as a whole. How can I do it by column?

pd.qcut(df, 10, labels=False)

Thanks.

James
  • 32,991
  • 4
  • 47
  • 70
  • Possibly related: [pandas find percentile stats of a given column](https://stackoverflow.com/questions/39581893/pandas-find-percentile-stats-of-a-given-column) – jpmc26 May 04 '18 at 05:20

1 Answers1

1

If you apply qcut across the columns you will get a dataframe where each entry is the rank value.

import numpy as np
import pandas as pd

data_a = np.random.random(100)
data_b = 100*np.random.random(100)

df = pd.DataFrame(columns=['A','B'], data=list(zip(data_a, data_b)))
rank = df.apply(pd.qcut, axis=0, q=10, labels=False)
Robbie
  • 4,672
  • 1
  • 19
  • 24