title: Python Pandas Dataframe replace values below treshold
body: <p>How can I apply a function element-wise to a pandas DataFrame and pass a column-wise calculated value (e.g. quantile of column)? For example, what if I want to replace all elements in a DataFrame (with <code>NaN</code>) where the value is lower than the 80th percentile of the column?</p>
  
  <pre><code>def _deletevalues(x, quantile):
  if x &lt; quantile:
      return np.nan
  else:
      return x
  
  df.applymap(lambda x: _deletevalues(x, x.quantile(0.8)))
  </code></pre>
  
  <p>Using <code>applymap</code> only allows one to access each value individually and throws (of course) an <code>AttributeError: ("'float' object has no attribute 'quantile'</code></p>
  
  <p>Thank you in advance.</p>