gpt4 book ai didi

python - Pandas 的移动平均线

转载 作者:行者123 更新时间:2023-12-01 01:47:21 24 4
gpt4 key购买 nike

我有一个包含 3 列的 csv 文件,我想获取 1 列的移动平均值。我想创建一个包含移动平均线的新列。

import pandas as pd

df= pd.read_csv('csv',usecols=['speed','col2', 'col3'])
df['MA'] = df.rolling( window=5, on='speed').mean
print(df)

它不再向我显示任何列。只有索引和...。

1   ...
2 ...
3 ...
3 ...
4 ...

[4 rows x 4 columns]

如果我更改为:

df= df.rolling(window=5, on='speed').mean
print(df)

它只返回给我这个:

<bound method Rolling.mean of Rolling [window=5,center=False,axis=0,on=speed]>

Process finished with exit code 0

最佳答案

另一种发布方式。

     df['MA'] = df['speed'].rolling(window=5).mean()

关于python - Pandas 的移动平均线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51137395/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com