Gaussian kernel density smoothing for pandas.DataFrame.resample?

I use pandas.DataFrame.resample

to reprogram random events to 1 hour intervals and see very stochastic results that don't seem to disappear if I increase the interval to 2 or 4 hours. This leaves me wondering if Pandas has a method of any kind for creating a smoothed density kernel, such as the Gaussian kernel density method, with an adjustable bandwidth to control the antialiasing. I don't see anything in the documentation, but thought I'd post here before posting to the developers server as that is their preference. Scikit-Learn has exactly the Gaussian kernel density function I want , so I'll try to use it, but it would be a fantastic addition to Pandas.

Any help is greatly appreciated!

hourly[0][344:468].plot()

      

enter image description here

+3


source to share


2 answers


Pandas has the ability to apply rolling window aggregation. The parameter win_type

controls the shape of the window. The parameter center

can be set so that the labels are set in the center of the window instead of the right edge. To do Gaussian smoothing:

hrly = pd.Series(hourly[0][344:468])
smooth = hrly.rolling(window=5, win_type='gaussian', center=True).mean(std=0.5)

      



http://pandas.pydata.org/pandas-docs/stable/computation.html#rolling

+4


source


Now I found that this option is available in pandas.stats.moments.ewma

and it works really well. Here are the results:

from pandas.stats.moments import ewma

hourly[0][344:468].plot(style='b')
ewma(hourly[0][344:468], span=35).plot(style='k')

      



enter image description here

+2


source







All Articles