title: How to use ast.literal_eval in a pandas dataframe and handle exceptions
body: <p>I have a <code>dataframe</code> with a column containing a <code>tuple</code> data as a string. Eg. <code>'(5,6)'</code>. I need to convert this to a tuple structure. One way of doing it is using the ast.literal_eval(). I am using it in this way.</p>
  
  <pre><code>df['Column'] = df['Column'].apply(ast.literal_eval)
  </code></pre>
  
  <p>Unfortunately, my data in this column contains empty strings also. The <code>ast.literal_eval()</code> is not able to handle this. I get this error.</p>
  
  <p><code>SyntaxError: unexpected EOF while parsing</code></p>
  
  <p>I am unsure if this is because it is unable to handle such a character. Based on my reading, I found that <code>ast.literal_eval()</code> works only in cases when a list, dict or tuple is there inside a string structure. </p>
  
  <p>To overcome this I tried to create my own function and return an empty string if it raises an exception.</p>
  
  <pre><code>def literal_return(val):
      try:
          return ast.literal_eval(val)
      except ValueError:
          return (val)
  
  df['Column2'] = df['Column'].apply(literal_return)
  </code></pre>
  
  <p>Even in this case, the same error pops up. How do we handle this. It would be great even if there is a way to ignore certain rows to apply the function and apply on the rest. Any help is appreciated.</p>