title: Replacing newlines with spaces for str columns through pandas dataframe
body: <p>Given an example dataframe with the 2nd and 3rd columns of free text, e.g.</p>
  
  <pre><code>&gt;&gt;&gt; import pandas as pd
  &gt;&gt;&gt; lol = [[1,2,'abc','foo\nbar'], [3,1, 'def\nhaha', 'love it\n']]
  &gt;&gt;&gt; pd.DataFrame(lol)
     0  1          2          3
  0  1  2        abc   foo\nbar
  1  3  1  def\nhaha  love it\n
  </code></pre>
  
  <p>The goal is to replace the <code>\n</code> to <code></code> (whitespace) and strip the string in column 2 and 3 to achieve:</p>
  
  <pre><code>&gt;&gt;&gt; pd.DataFrame(lol)
     0  1         2        3
  0  1  2       abc  foo bar
  1  3  1  def haha  love it
  </code></pre>
  
  <p><strong>How to replace newlines with spaces for specific columns through pandas dataframe?</strong></p>
  
  <p>I have tried this:</p>
  
  <pre><code>&gt;&gt;&gt; import pandas as pd
  &gt;&gt;&gt; lol = [[1,2,'abc','foo\nbar'], [3,1, 'def\nhaha', 'love it\n']]
  
  &gt;&gt;&gt; replace_and_strip = lambda x: x.replace('\n', ' ').strip()
  
  &gt;&gt;&gt; lol2 = [[replace_and_strip(col) if type(col) == str else col for col in list(row)] for idx, row in pd.DataFrame(lol).iterrows()]
  
  &gt;&gt;&gt; pd.DataFrame(lol2)
     0  1         2        3
  0  1  2       abc  foo bar
  1  3  1  def haha  love it
  </code></pre>
  
  <p>But there must be a better/simpler way.</p>