trend_tools.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:scikit-discovery 作者: MITHaystack 项目源码 文件源码
def medianFilter(data, window, interpolate=True):
    '''
    A median filter

    If interpolate is True, data will be interpolated before smoothering.
    Otherwise, all available data within the window will be used

    @param data: Input data
    @param window: Size of filter window
    @param interpolate: Interpolate data before smoothing

    @return Smoothed data
    '''

    if interpolate == True:
        data = interpNaN(data)
        result = pd.Series(median_filter(data, size=window), index=data.index)

    else:
        result = data.copy()
        for index, value in data.iteritems():
            if not pd.isnull(value):
                result.loc[index] = np.nanmedian(data[np.logical_and(data.index > index-window/2,
                                                                     data.index < index+window/2)])

    return result
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号