我是pandas的新手。我正在使用pandas读取一个包含时间戳记录的CSV文件,并将其读入数据框中。该数据具有以下列:
时间戳 COLUMN_A COLUMN_B COLUMN_C
将数据读入数据框后,我想能够在COLUMN_C上运行窗口函数;该函数应返回列的时间戳值。
我已经为可迭代对象编写了一些代码:
import collections
import itertools
def sliding_window_iter(iterable, size):
"""Iterate through iterable using a sliding window of several elements.
Creates an iterable where each element is a tuple of `size`
consecutive elements from `iterable`, advancing by 1 element each
time. For example:
>>> list(sliding_window_iter([1, 2, 3, 4], 2))
[(1, 2), (2, 3), (3, 4)]
"""
iterable = iter(iterable)
window = collections.deque(
itertools.islice(iterable, size-1),
maxlen=size
)
for item in iterable:
window.append(item)
yield tuple(window)
我该如何修改这个操作,使它能够在数据框的列上工作呢?