pandas 在滚动窗口上执行多重分析,Python

bq3bfh9z  于 2023-05-21  发布在  Python
关注(0)|答案(1)|浏览(185)

我试图同时对两个单独的DataFrame执行多个分析。我想首先对两个pandas DataFrame进行去趋势化,然后对两个数据集的同一窗口应用自定义函数。任何关于如何处理这一点的帮助将不胜感激。

uyto3xhc

uyto3xhc1#

您可以从scipy使用detrend。下面是一个例子:

import pandas as pd
import numpy as np
from scipy.signal import detrend

data1 = np.random.rand(100)
data2 = np.random.rand(100)

df1 = pd.DataFrame(data1, columns=['Data1'])
df2 = pd.DataFrame(data2, columns=['Data2'])

def custom_function(window_data):
    return np.mean(window_data)

window_size = 10
stride = 5

df1_detrended = pd.DataFrame(detrend(df1['Data1']), columns=['Data1'])
df2_detrended = pd.DataFrame(detrend(df2['Data2']), columns=['Data2'])

相关问题