[英]Moving average in Pandas
我有一个包含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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.