title: Python Pandas - Highlighting maximum value in column
body: <p>I have a dataframe produced by this code:</p>
  
  <pre><code>hmdf = pd.DataFrame(hm01)
  new_hm02 = hmdf[['FinancialYear','Month']]
  new_hm01 = hmdf[['FinancialYear','Month','FirstReceivedDate']]
  
  hm05 = new_hm01.pivot_table(index=['FinancialYear','Month'], aggfunc='count')
  vals1 = ['April    ', 'May      ', 'June     ', 'July     ', 'August   ', 'September', 'October  ', 'November ', 'December ', 'January  ', 'February ', 'March    ']
  
  df_hm = new_hm01.groupby(['Month', 'FinancialYear']).size().unstack(fill_value=0).rename(columns=lambda x: '{}'.format(x))
  df_hml = df_hm.reindex(vals1)
  </code></pre>
  
  <p>And then I have a function to highlight the maximum value in each column:</p>
  
  <pre><code>def highlight_max(data, color='yellow'):
      '''
      highlight the maximum in a Series or DataFrame
      '''
      attr = 'background-color: {}'.format(color)
      if data.ndim == 1:  # Series from .apply(axis=0) or axis=1
          is_max = data == data.max()
          return [attr if v else '' for v in is_max]
      else:  # from .apply(axis=None)
          is_max = data == data.max().max()
          return pd.DataFrame(np.where(is_max, attr, ''),
                              index=data.index, columns=data.columns)
  </code></pre>
  
  <p>And then this code: <code>dfPercent.style.apply(highlight_max)</code> produces this:</p>
  
  <p><a href="https://i.stack.imgur.com/HTr8p.png" rel="noreferrer"><img src="https://i.stack.imgur.com/HTr8p.png" alt="enter image description here"></a></p>
  
  <p>As you can see, only the first and last column have the correct max value highlighted.</p>
  
  <p>Anyone know what is going wrong?</p>
  
  <p>Thank you</p>