滚动直方图 window (Python)

Histogram with rolling window (Python)

我正在尝试为 DataFrame 中的每个滚动 window 创建一个直方图。 Python中的rolling函数(df.WaveData.rolling(14).mean())可以用来求和或求平均值,但是如何用它来绘制每个window中数据的直方图呢? ?

import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-10, 10, 1000)
y = np.sin(x)
plt.plot(x, y)
plt.show()


df = pd.DataFrame(y, columns=['WaveData'])
print(df)
print(df.WaveData.rolling(14).mean())

**Ideal**:
    for data in window:
        histogram(data_in_window)
        n, edges = np.histogram(data, bins=25)

给你:

import matplotlib.pyplot as plt 
import pandas as pd

# generate random dataframe
df = pd.DataFrame(np.random.randint(0,1000,size=(1000, 4)), columns=list('ABCD'))

window_size = 100
for i in range(len(df.A.values)):
    window = df.A.values[i:i+window_size]
    n, bins, patches = plt.hist(window, 25)
    plt.show()