熊猫错误:试图在DataFrame的切片副本上设置值

时间:2020-09-29 14:38:59

标签: python pandas

df_play = pd.read_csv("players_stats_by_season_full_details.csv")

VC = df_play[df_play["League"] == "NBA"]
VC

VC["FT_Miss"] = VC['FTA'] - VC['FTM']

错误消息:

A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

1 个答案:

答案 0 :(得分:1)

VC不是数据帧,它是原始数据的一部分,意味着它只是指向df_play的指针

尝试;

VC = df_play[df_play["League"] == "NBA"].copy()