title: applying a method to a few selected columns in a pandas dataframe
body: <p>I would like to apply a little method to several columns in a Dataframe. The method color_negative can't be applied to columns with strings, therefore I need to skip these columns somehow. I could think of two approaches to solve the problem, though sadly none is working.</p>
  <ul>
  <li><p><strong>In approach 1:</strong></p>
  <p>I try to apply the method to every column one by one skipping the first one by using the index of the Dataframe and by setting the incrementing counter of the while loop to 1. When executing this approach I get the error, that the 'Series' object has no attribute 'style', so apparently, I can't apply a method to a single column.</p>
  </li>
  <li><p><strong>In approach 2:</strong></p>
  <p>I try to use the subset to apply the method only to those columns with numeric values, though I'm not sure if I use subset correctly. When executing this approach I get the error that the object of type 'Styler' has no <code>len()</code>.</p>
  </li>
  </ul>
  <p>Here a simplified example:</p>
  <pre><code>import pandas as pd
  
  d = {'col1': ['a', 'b'], 'col2': [21, 22], 'col3': [3, 51]}
  df = pd.DataFrame(data=d)
  
  def color_negative_red(val):
      color = 'black'
      if val &lt; -1 : color = 'red'
      if val &gt; 1 :  color = 'green'
      return 'color: %s' % color    
      
  i=1
  while i &lt;= len(df):
      #Approach 1
      df.iloc[:, i] = df.iloc[:, i].style.applymap(color_negative_red)
      #Approach 2
      df = df.style.applymap(color_negative_red, subset = df.iloc[:, i])
      i+=1    
  
  df
  </code></pre>
  <p>Has anyone a suggestion on how to solve this problem?</p>