title: How to get a robust nonlinear regression fit using scipy.optimize.least_squares?
body: <p>My specific issue is that I cannot seem to get my data to converted to floating points. I have data and simply want to fit a robust curve using my model equation:</p>
  
  <blockquote>
    <p>y = a * e^(-b*z)</p>
  </blockquote>
  
  <p>This cookbook is my reference: <a href="https://scipy-cookbook.readthedocs.io/items/robust_regression.html" rel="nofollow noreferrer">click</a></p>
  
  <p>Below is my attempt. I am getting this: </p>
  
  <blockquote>
    <p>TypeError: 'data type not understood'</p>
  </blockquote>
  
  <p>which I believe is because my columns are strings, so I tried <code>pd.Series.astype()</code>.</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  import matplotlib.pyplot as plt
  from scipy.optimize import least_squares
  
  for i in range(1):
  
      def model(z, a, b):
          y = a * np.exp(-b * z)
          return y
      data = pd.read_excel('{}.xlsx'.format(600+i), names = ['EdGnd','380','395','412','443','465','490','510','520','532','555','560','565','589','625','665','670','683','694','710','Temp','z','EdZTemp','Tilt','Roll','EdZVin'])
      data.dropna(axis = 0, how = 'any')
      data.astype('float')
      np.dtype(data)
      data.plot.scatter('z','380') 
      def fun(x, z, y):
          return x[0] * np.exp(-x[1] * z) - y
      x0 = np.ones(3)
      rbst1 = least_squares(fun, x0, loss='soft_l1', f_scale=0.1, args=('z', 'ed380'))
      y_robust = model('z', *rbst1.x)
      plt.plot('z', y_robust, label='robust lsq')
      plt.xlabel('$z$')
      plt.ylabel('$Ed$')
      plt.legend();
  </code></pre>