title: Pandas read_csv converter – How to handle exceptions (literal_eval SyntaxError)
body: <p>Into a Pandas DataFrame, I'm reading a csv file that looks like:</p>
  
  <blockquote>
  <pre><code>          A              B
    +--------------+---------------+
  0 |              | ("t1", "t2")  |
    +--------------+---------------+
  1 | ("t3", "t4") |               |
    +--------------+---------------+
  </code></pre>
  </blockquote>
  
  <p>Two of the cells have literal tuples in them, and two of the cells are empty.</p>
  
  <pre><code>df = pd.read_csv(my_file.csv, dtype=str, delimiter=',',
      converters={'A': ast.literal_eval, 'B': ast.literal_eval})
  </code></pre>
  
  <p>The converter <code>ast.literal_eval</code> works fine to convert the literal tuples into Python tuple objects within the code – but only as long as there are no empty cells. Because I have empty cells, I get the error:</p>
  
  <blockquote>
    <p>SyntaxError: unexpected EOF while parsing</p>
  </blockquote>
  
  <p>According to this <a href="https://stackoverflow.com/a/14635052/4909923">S/O answer</a>, I should try to catch the SyntaxError exception for empty strings:</p>
  
  <blockquote>
    <p>ast uses compile to compile the source string (which must be an
    expression) into an AST. If the source string is not a valid
    expression (like an empty string), a SyntaxError will be raised by
    compile.</p>
  </blockquote>
  
  <p>However, I am not sure how to catch exceptions for individual cells, within the context of the <code>read_csv</code> <code>converters</code>. </p>
  
  <p>What would be the best way to go about this? Is there otherwise some way to convert empty strings/cells into objects which <code>literal_eval</code> would accept or ignore?</p>
  
  <p>NB: My understanding is that having literal tuples in readable files isn't always the best thing, but in my case it's useful.</p>