Added resampling timeseries operation
@@ -6,6 +6,54 @@ from ..core.util import pd
from ..element import Scatter
+class rolling(ElementOperation):
+ """
+ Applies a function over a rolling window.
+ """
+
+ center = param.Boolean(default=True, doc="""
+ Whether to set the x-coordinate at the center or right edge
+ of the window.""")
+
+ function = param.Callable(default=np.mean, doc="""
+ The function to apply over the rolling window.""")
+
+ rolling_window = param.Integer(default=10, doc="""
+ The window size over which to apply the function.""")
+
+ def _apply(self, element, key=None):
+ xdim = element.kdims[0].name
+ df = df.rolling(window=self.p.rolling_window, center=self.p.center, on=xdim)
+ return element.clone(df.apply(self.p.function).reset_index())
+
+ def _process(self, element, key=None):
+ return element.map(self._apply, Element)
+
+
+class resample(ElementOperation):
+ """
+ Resamples a timeseries of dates with a frequency and function
+ """
+
+ edge = param.ObjectSelector(default='right', doc="""
+ The bin edge to label the bin with.""")
+
+ function = param.Callable(default=np.mean, doc="""
+ The function to apply over the rolling window.""")
+
+ rule = param.String(default='D', doc="""
+ A string representing the time interval over which to apply the resampling""")
+
+ def _apply(self, element, key=None):
+ xdim = element.kdims[0].name
+ df = element.dframe()
+ df = df.resample(rule=self.p.rule, label=self.p.edge, on=xdim)
+ return element.clone(df.apply(self.p.function).reset_index())
+
+ def _process(self, element, key=None):
+ return element.map(self._apply, Element)
+
+
class rolling_outlier_std(ElementOperation):
"""
Detect outliers for using the standard devitation within a rolling window.
@@ -35,28 +83,3 @@ class rolling_outlier_std(ElementOperation):
def _process(self, element, key=None):
return element.map(self._apply, Element)
-
-
-class rolling(ElementOperation):
- """
- Applies a function over a rolling window.
- """
-
- center = param.Boolean(default=False, doc="""
- Whether to set the x-coordinate at the center or right edge
- of the window.""")
-
- function = param.Callable(default=np.mean, doc="""
- The function to apply over the rolling window.""")
-
- rolling_window = param.Integer(default=10, doc="""
- The window size over which to apply the function.""")
-
- def _apply(self, element, key=None):
- df = element.dframe().set_index(element.kdims[0].name)
- df = df.rolling(window=self.p.rolling_window,
- center=self.p.center).apply(self.p.function)
- return element.clone(df.reset_index())
-
- def _process(self, element, key=None):
- return element.map(self._apply, Element)
