首页 > 解决方案 > 熊猫无法设置没有定义索引的框架和无法转换为系列的值

问题描述

df_players.loc[df_players['Player']=='Vitor Gabriel'][['Points']]

印刷:

           Points
407           0.0
18805         0.0
19634         0.0
20459         7.2
21285         0.0
22111         0.0
22936         0.0

现在如果我这样做:

a1_points = df_players.loc[df_players['Player']=='Vitor Gabriel'][['Points']]
a1_points['RollingAvg'] = a1_points.rolling(window=4, center=False).mean()

我得到错误:

ValueError: Cannot set a frame with no defined index and a value that cannot be converted to a Series

我错过了什么?

标签: pythonpandas

解决方案


第二行需要先转换为系列

a1_points['RollingAvg'] = a1_points.Points.rolling(window=4, center=False).mean()

推荐阅读