【发布时间】:2021-08-26 14:53:48
【问题描述】:
我有一个包含一列列表的 df。
Python Pandas rolling aggregate a column of lists
import pandas as pd
import numpy as np
# Get some time series data
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/timeseries.csv")
input_cols = ['A', 'B']
df['single_input_vector'] = df[input_cols].apply(tuple, axis=1).apply(list)
我想知道是否有办法为给定窗口创建“single_input_vector”列的滚动聚合。我查看了以下 SO 链接,但它没有提供包含窗口的方法。在我的情况下,窗口 3 的所需输出列将是:
Row1: [[24.68, 164.93]]
Row2: [[24.68, 164.93], [24.18, 164.89]]
Row3: [[24.68, 164.93], [24.18, 164.89], [23.99, 164.63]]
Row4: [[24.18, 164.89], [23.99, 164.63], [24.14, 163.92]]
等等。
【问题讨论】:
标签: python list dataframe window rolling-computation