我有一个包含 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