title: Convert data to the quantile bin
body: <p>I have a dataframe with numerical columns. For each column I would like calculate quantile information and assign each row to one of them. I tried to use the <a href="http://pandas.pydata.org/pandas-docs/dev/groupby.html?highlight=qcut" rel="noreferrer"><code>qcut()</code> method</a> to return a list of bins but instead ended up calculating the bins individually.  What I thought might exist but I couldn't find it would be a method like <code>df.to_quintile(num of quantiles)</code>.  This is what I came up with but I am wondering if there is a more succint/pandas way of doing this.</p>
  
  <pre><code>import pandas as pd
  
  #create a dataframe
  df = pd.DataFrame(randn(10, 4), columns=['A', 'B', 'C', 'D'])
  
  def quintile(df, column):
      """
      calculate quintiles and assign each sample/column to a quintile 
      """
      #calculate the quintiles using pandas .quantile() here
      quintiles = [df[column].quantile(value) for value in [0.0,0.2,0.4,0.6,0.8]]
      quintiles.reverse() #reversing makes the next loop simpler
  
      #function to check membership in quintile to be used with pandas apply
      def check_quintile(x, quintiles=quintiles):
          for num,level in enumerate(quintiles):
              #print number, level, level[1]
              if  x &gt;= level:
                  print x, num
                  return num+1
  
      df[column] = df[column].apply(check_quintile)
  
  quintile(df,'A')
  </code></pre>
  
  <p>thanks,
  zach cp</p>
  
  <p>EDIT: After seeing DSMs answer the function can be written much simpler (below). Man, thats sweet.</p>
  
  <pre><code>def quantile(column, quantile=5):
      q = qcut(column, quantile)
      return len(q.levels)- q.labels
  df.apply(quantile)
  #or
  df['A'].apply(quantile)
  </code></pre>