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

a = pd.DataFrame({'a':[1,2,3],'b':[1,2,3]})
print(a)

在这里插入图片描述
用如下代码形式会出差:

a[a['a']==1]['b'] =0
print(a)

A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer..._第1张图片
正确用法为:

a.loc[a['a']==1,'b'] = 0
print(a)

在这里插入图片描述

你可能感兴趣的:(python,python)