title: Most efficient way to convert empty(ish) strings to null
body: <p>I have a pandas series that contains both empty strings and strings with nothing but whitespace. I want to convert these to a 'null' value (e.g. None).</p>
  
  <pre><code>def empty_str_to_null(s):
      """Convert empty strings to None (null)"""
      s.loc[s.str.strip().str.len() == 0] = None
      return s
  
  foo = pd.Series(np.repeat([1,2,3,'',None,np.NaN, '  ', '  a'],1E6))
  
  &gt;&gt;&gt; %time bar = empty_str_to_null(foo)
  </code></pre>
  
  <p>This works but isn't that fast. </p>
  
  <pre><code>CPU times: user 7.67 s, sys: 260 ms, total: 7.93 s
  Wall time: 8.38 s
  </code></pre>
  
  <p>I will need to do this repeatedly for many different fields.</p>
  
  <p>Is there a better (quicker) way?</p>