0

I have the graph below, which is a result of a plot of a two-column data frame, which I'm simply plotting as

df.plot(style='o-')

EDIT

And I plot the running average of it (thanks to the help of people below) with: df.rolling(5).mean()

Can I use some function from pandas to plot the derivative of the y-axis over the x-axis?

I've tried the solution proposed here: python pandas: how to calculate derivative/gradient But it didn't work

enter image description here

ziulfer
  • 1,339
  • 5
  • 18
  • 30

2 Answers2

1

What you would like to have may not be 'average' but 'smoothing' or 'regression', google for those terms can give you more relevent result.

As for your question, Savitzky–Golay filter could be a good tool to use here, it does convolution "by fitting successive sub-sets of adjacent data points with a low-degree polynomial".

In Python you can use scippy.signal.savgol_filter to get the smoothed points.
The derivative would be more tricky though,a workaround would be calculate the slope with convoluted signal(points).

Hongpei
  • 677
  • 3
  • 13
1

Like already explained, it seams that you want to apply same kind of filter instead of run an average (that in your case should return a number). To start, you can try a simple moving average doing:

df.rolling(5).mean()

Where 5 is the window.

nunodsousa
  • 2,635
  • 4
  • 27
  • 49