标签:tin panda 元素 问题解决 col 就会 trying 问题 出现
先从原dataframe取出一个子dataframe,然后再对其中的元素赋值,例如
s = d[d['col_1'] == 0]
s.loc[:, 'col_2'] = 1
就会出现报错:
SettingWithCopyWarning: 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
解决方法:
s = d[d['col_1'] == 0].copy()
s.loc[:, 'col_2'] = 1
[问题解决]pandas DataFrame中经常出现SettingWithCopyWarning
标签:tin panda 元素 问题解决 col 就会 trying 问题 出现
原文地址:https://www.cnblogs.com/everfight/p/SettingWithCopyWarning.html