0

I have data in CSV file, I am extracting data using iloc into variables. So I have 2 series one is the data and the other is time. I want to derivate the data with respect to time and then plot the Derivate data.

DY=misc.derivative(YR,TR)
plt.plot(DY)
plt.show()

I am getting this error TypeError: 'Series' object is not callable YR and TR are Panda Series I am getting this output by print(YR) and Print(TR)

0           0
1          10
2          20
3          30
4          40
        ...  
3758    37578
3759    37588
3760    37598
3761    37608
3762    37618
Name: timestamp, Length: 3763, dtype: int64

0      -79.488485
1      -79.451540
2      -79.413175
3      -79.379011
4      -79.339471
          ...    
3758   -79.430326
3759   -79.498313
3760   -79.574641
3761   -79.664465
3762   -79.776534
Name: Y, Length: 3763, dtype: float64
  • 1
    You might want `np.gradient`. Mathematiacally we talk about a `derivative of a function`. Mathematically that's the `slope`, change in `y` as the `x` steps become smaller. Numerically we approximate that differences or `gradients`. In any case, spend time reading the function documentation, and experimenting with the examples as needed. – hpaulj Aug 29 '22 at 01:07
  • 1
    More discussion on `pd.Series.diff` and `np.gradient` at https://stackoverflow.com/questions/41780489/python-pandas-how-to-calculate-derivative-gradient. Also look at `np.diff`. – hpaulj Aug 29 '22 at 01:10

1 Answers1

1

Look at the function signature of misc.derivative: https://docs.scipy.org/doc/scipy/reference/generated/scipy.misc.derivative.html

The first argument is a callable, which is why you get the Series not callable error. Scipy.misc.derivative seems to be used for evaluating derivatives of an analytical function numerically, which is not what you are attempting to do. It seems like you want to do some stenciling to approximate derivatives instead.

JKJK
  • 31
  • 1
  • 5