title: Changing pandas strings to integer or float using `try: except:`
body: <p>I have a dataframe full of strings that I would rather have as integers, or where that is not possible, floats.</p>
  <p>I have tried to achieve this using <code>try: except:</code>.</p>
  <p>The string <code>&quot;30&quot;</code> becomes an integer, but the string <code>&quot;40.0&quot;</code> becomes a float. I would like a column containing only whole-numbers as strings (<code>&quot;35.0&quot;, &quot;41.0&quot;, &quot;55.0&quot;</code>) to become integers.</p>
  <p>Here is a version of what I have attempted:</p>
  <pre><code>import pandas as pd
  
  data = {
          'Name':['Tom', 'Dick', 'Harry'],
          'Age':['20', '21', '19'],
          'Height':['1.73', '1.80', '1.59'],
          'Score':['72.0', '69.0', '68.0']
          }
  df = pd.DataFrame(data)
  
  # Make list for looping through columns
  cols = df.columns
  
  # Check data types before manipulation
  print(df.dtypes)
  
  # Change to integer, or where not possible, float
  for col in cols:
      try:
          df[col] = df[col].astype('int')
          continue
      except ValueError:
          pass
      try:
          df[col] = df[col].astype('float')
      except ValueError:
          pass
  
  # Check if manipulation was successful
  print(df.dtypes)
  </code></pre>