📜  试图在 DataFrame 中的切片副本上设置一个值.尝试改用 .loc[row_indexer,col_indexer] = value - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:56             🧑  作者: Mango

代码示例3
df[df['A'] > 2]['B'] = new_val  # new_val not set in df
# rewrite it as below
df.loc[df['A'] > 2, 'B'] = new_val