在窗口中使用迭代刀柄的数据集

Dataset using iterative hilt in windowing

这是我的真实代码,但我没有真正的输出

import itertools as it
import numpy as np
import pandas as pd

x = [1,2,3,4,5,6,7,8,9,10]
def moving_window(x, length, step=1):
    streams = it.tee(x, length)
    return zip(*[it.islice(stream, i, None, step+2) for stream, i in zip( streams,it.count(step=step))])
x_=list(moving_window(x,6))

for i in range(len(x_)):
    globals()['a'+str(i)] = list(x_[i])
    print(x_[i])

def mean(dataset):
    return sum(dataset) / len(dataset)
for i in range(len(x_)):
    globals()['a'+str(i)] = list(x_[i])
    a=mean(x_[i])
    print(a)

现在的输出是:

   3.5
   6.5

但我想要一个具有以下输出的代码:

| A header | Another header |


| a1   | 3.5           |

| a2   | 6.5           |

这些行和列继续

你想要这个吗:

dct = {}
for i in range(len(x_)):
    globals()['a'+str(i)] = list(x_[i])
    a=mean(x_[i])
    dct[f'a{i+1}'] = a
    print(a)

输出:

>>> dct
{'a1': 3.5, 'a2': 6.5}

更新:

>>> df = pd.DataFrame(dct.items(), columns=['A header', 'Another header'])
>>> df
    A header    Another header
0         a1    3.5
1         a2    6.5