python - 熊猫无法设置没有定义索引的框架和无法转换为系列的值
问题描述
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
我错过了什么?
解决方案
第二行需要先转换为系列
a1_points['RollingAvg'] = a1_points.Points.rolling(window=4, center=False).mean()
推荐阅读
- angular - 当日期格式为 dd.MM.yyyy 时,ng-zorro、nz-statistic 组件不呈现年份
- python - 熊猫中的字符串规则
- algorithm - 将二分搜索算法升级为更复杂的算法
- bit-manipulation - 演练:使用位操作对 2 个整数求和
- mongodb - GraphQl API 中的 AccessDenied 错误,无法弄清楚
- mobile - Anbox:在使用这些应用程序时,移动设备上是否有任何原生计算?还是整个应用程序在云上运行并流式传输?
- string - 通过 Visual Studio Code 中的热键将格式化的 PowerShell 哈希表/数组定义转换为单行(反之亦然)
- django - Django 重定向后两页
- bash - Bash 脚本 - 传递给脚本的运行函数
- visual-studio-code - VS Code - 为自定义文件扩展名应用语法高亮/格式化