title: Exponential curve fitting of pandas data in python
body: <p>I'm trying to fit an exponential curve to some data represented by a pandas dataframe. The data looks like this:</p>
  <p><a href="https://i.stack.imgur.com/3rVsf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3rVsf.png" alt="enter image description here" /></a></p>
  <p>The code I've used for curve fitting:</p>
  <pre><code>import pandas as pd
  import numpy as np
  from matplotlib import pyplot as plt
  from scipy.optimize import curve_fit
  
  t = df['time'].values
  ym = df['value'].values
  
  def func(t, c0, c1, c2, c3):
      return c0 + c1*t - c2*np.exp(-c3*t)
  
  p0 = [6e6, 0.01, 100, 0.01]
  c, cov = curve_fit(func, t, ym, p0)
  
  print(c) # Output: [-5.46019366e+06  3.19567938e+03  1.00000000e+08  1.00000000e+06]
  
  yp = func(t, c[0], c[1], c[2], c[3])
  
  plt.figure()
  plt.plot(t/60, ym)
  plt.plot(t/60, yp)
  </code></pre>
  <p>However, the fitted curve always seem to be linear like this:</p>
  <p><a href="https://i.stack.imgur.com/Ipll3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ipll3.png" alt="enter image description here" /></a></p>
  <p>I have tried different methods I've found online and always get the same linear result. My dataframe look like this, were Cycle_id corresponds to &quot;time&quot;, and peak correspond to &quot;value&quot;:</p>
  <p><a href="https://i.stack.imgur.com/E6tUg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E6tUg.png" alt="enter image description here" /></a></p>
  <p>Any suggestion on how to fit this data is much appreciated, since I can't seem to find any errors in my code upon reviewing it, thus not getting any further..</p>