解决 SettingWithCopyWarning Try using .loc[row_indexer,col_indexer] = value instead

利用 Pandas 向 DataFrame 中插入一列数据时,出现警告:

1
2
3
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

解决办法:

先 copy 一份数据。

1
2
a = a.copy()
a['column'] = Your List

解决 SettingWithCopyWarning Try using .loc[row_indexer,col_indexer] = value instead
https://wonderhoi.com/2023/11/28/解决-SettingWithCopyWarning-Try-using-loc-row-indexer-col-indexer-value-instead/
作者
wonderhoi
发布于
2023年11月28日
许可协议