You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将DataFrame中迈克尔·乔丹和拉里·伯德的FPPG值修改为0?

解决指定球员FPPG值修改为0的问题

需求说明

将DataFrame中指定球员的FPPG值修改为0。

现有代码与数据

读取数据的代码:

import pandas as pd
raw_data = pd.read_csv(r'C:\DFS\nFire12_31_2022.csv')

原始DataFrame数据:

Players         FPPG
 Luka Doncic     60
 Micheal Jordon  72
 Larry Bird      75

需要修改的球员列表:

players_to_remove = ['Micheal Jordon','Larry Bird']

实现代码

使用pandas.DataFrame.loc定位指定球员,直接修改FPPG值为0:

# 定位指定球员并修改FPPG为0
raw_data.loc[raw_data['Players'].isin(players_to_remove), 'FPPG'] = 0

执行后得到的结果:

Players         FPPG
 Luka Doncic     60
 Micheal Jordon  0
 Larry Bird      0

代码说明

  • raw_data['Players'].isin(players_to_remove):筛选出Players列属于指定列表的行
  • loc[筛选条件, 'FPPG'] = 0:将符合条件的行的FPPG字段赋值为0

内容的提问来源于stack exchange,提问作者ThIeN TrAn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.05 18:10:34