title: How to use max in a lambda function applied to a pandas DataFrame
body: <p>I'm trying to apply a lambda function to a pandas Dataframe that return the difference between each row and the max of that column.</p>
  
  <p>It can be easily achieved by using a separate variable and setting that to the max of the column, but I'm curious how it can be done in a single line of code.</p>
  
  <pre class="lang-py prettyprint-override"><code>import pandas as pd
  
  df = pd.DataFrame({
      'measure': [i for i in range(0,10)]
  })
  
  col_max = df.measure.max()
  df['diff_from_max'] = df.apply(lambda x: col_max - x['measure'], axis=1)
  </code></pre>