title: Change dtypes in Pandas DataFrame cell-by-cell
body: <p><strong>Problem:</strong></p>
  
  <p>I have a Pandas.DataFrame which stores only unicode values. Each column contains values that could be converted to either an integer or float, or left as unicode. (Python version 2.7.15, Pandas version 0.23.0)</p>
  
  <pre><code>df = pd.DataFrame({'x':[u'1', u'1.23', u'', u'foo_text'], 'y':[u'bar_text', u'', u'2', u'4.56']})
  print df
            x         y
  0         1  bar_text
  1      1.23
  2                   2
  3  foo_text      4.56
  </code></pre>
  
  <p>I would like to convert the type of each cell as follows:</p>
  
  <ol>
  <li>If possible to convert to int, convert to int</li>
  <li>Else if possible to convert to float, convert to float</li>
  <li>Else, leave as unicode</li>
  </ol>
  
  <p><strong>Solution attempts:</strong></p>
  
  <p>The following code does precisely what I want:</p>
  
  <pre><code>type_list = [int, float, unicode]
  for column in df.columns:
      for index in df.index:
          for desired_type in type_list:
              try:
                  df.loc[index,column] = desired_type(df.loc[index,column])
                  break
              except ValueError:
                  pass
  </code></pre>
  
  <p>The problem is that my actual DataFrame is >10 million cells, and this will way too long to execute. I am trying to find a faster way to do this.</p>
  
  <p>I have looked at <code>pandas.DataFrame.infer_objects()</code>, and <code>pandas.to_numeric()</code>, but neither appear to handle the case of mixed types within a column.</p>