title: How to change dtype of each dataframe column to float if it best fits?
body: <p>I have an excel that has columns with values like <code>1.32131**</code>, among columns of dtype <code>string</code>. As a result the dtypes of these columns in the dataframe are <code>object</code>. I have cleaned the asterisks from the dataframe and now I need to convert the dtypes of these columns to <code>float64</code>. I am aware of ways to do it if I define the columns that need to be changed or the desired dtypes for each column (like the functions mentioned <a href="https://stackoverflow.com/questions/15891038/change-column-type-in-pandas">here</a>), but I have too many columns to use such solutions. Thus I am looking for a more efficient and clean way.</p>
  <p>For example, if I wanted to convert to <code>int64</code> I would use <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.convert_dtypes.html#pandas.DataFrame.convert_dtypes" rel="nofollow noreferrer"><code>convert_dtypes()</code></a>, but it seems that it doesn't support floats and it returns these columns with <code>object</code> dtype.</p>
  <blockquote>
  <p>Then, if possible, convert to StringDtype, BooleanDtype or an
  appropriate integer extension type, otherwise leave as object.</p>
  </blockquote>
  <p>Right now I am using the following script that works but I think it's to big for its purpose and it a bit slow.</p>
  <pre><code># Create df and clean it
  # note that the data exist in an excel normally and the dict is only for reproducibility purposes
  dict = {'Name':['BPh1', 'BPh2', 'BPh3', 'BPh4', 'BPh5', 'BPh6', 'BPh7'], 'BBB':['2.00755**', '2.7766**', '0.490127**','0.490127**', '0.87667**', '0.899189**', '3.084**'], 'Buffer_solubility_mg_L':['0.00112934**','0.000798559**', '0.000218191**', '0.000122249**', '0.00382848**', '0.00109165**', '0.000665366**'], 'CYP_2C19_inhibition':['Inhibitor','Inhibitor','Non','Non','Inhibitor','Inhibitor',
  'Inhibitor']}
  
  ss =  pd.DataFrame(dict).replace(&quot;\*&quot;,'',regex=True)
  
  # Convert dtype to float when possible
  for col in ss.columns[1:]:
      print(col,'\n',ss[col].dtypes)
      try:
          ss[col] = pd.to_numeric(ss[col])
      except:
          pass
      print(ss[col].dtypes,'\n')
  </code></pre>
  <p>Is there a cleaner way to do this conversion?</p>