title: Pythonic/efficient way to strip whitespace from every Pandas Data frame cell that has a stringlike object in it
body: <p>I'm reading a CSV file into a DataFrame.  I need to strip whitespace from all the stringlike cells, leaving the other cells unchanged in Python 2.7.</p>
  
  <p>Here is what I'm doing:</p>
  
  <pre><code>def remove_whitespace( x ):
      if isinstance( x, basestring ):
          return x.strip()
      else:
          return x
  
  my_data = my_data.applymap( remove_whitespace )
  </code></pre>
  
  <p>Is there a better or more idiomatic to Pandas way to do this?</p>
  
  <p>Is there a more efficient way (perhaps by doing things column wise)?</p>
  
  <p>I've tried searching for a definitive answer, but most questions on this topic seem to be how to strip whitespace from the column names themselves, or presume the cells are all strings.</p>