Python 更改列中的值:SettingWithCopyWarning:试图在数据帧错误的切片副本上设置值

Python 更改列中的值:SettingWithCopyWarning:试图在数据帧错误的切片副本上设置值,python,pandas,Python,Pandas,所以我把它命名为matches,它有两列“Thread”和“Current email”。“当前电子邮件”是从另一个名为df的df复制的: matches['Current email'] = df['description'] 线程只有两个值:线程和非线程。因此,如果电子邮件是一个线程,我想将具有相同索引的“当前电子邮件”值更改为8(实际上是另一个值,但为了便于理解8) 运行此命令后,警告/usr/local/envs/py3env/lib/python3.5/site packages/i

所以我把它命名为matches,它有两列“Thread”和“Current email”。“当前电子邮件”是从另一个名为df的df复制的:

matches['Current email'] = df['description']
线程只有两个值:线程非线程。因此,如果电子邮件是一个线程,我想将具有相同索引的“当前电子邮件”值更改为8(实际上是另一个值,但为了便于理解8)

运行此命令后,警告/usr/local/envs/py3env/lib/python3.5/site packages/ipykernel/\uuuuu main\uuuuuu.py:5:SettingWithCopyWarning: 试图在数据帧的切片副本上设置的值出现

我试过这样的方法:

matches['Current email'] = df['description'].copy()
更有趣的是,相同的代码适用于其他数据


有什么帮助吗?

您可以使用布尔索引:

filter_thread = matches['Thread'] != 'not thread'
matches.loc[filter_thread, 'Current email'] = 8

可以使用布尔索引:

filter_thread = matches['Thread'] != 'not thread'
matches.loc[filter_thread, 'Current email'] = 8