Python SettingWithCopyWarning将空列添加到数据库中的数据帧时

Python SettingWithCopyWarning将空列添加到数据库中的数据帧时,python,pandas,dataframe,Python,Pandas,Dataframe,我有一个有两列的数据框。我正在尝试使用以下说明添加新的空列: df['new_col'] = '' 已添加列,但带有警告: <ipython-input-16-779f11834aea>: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 instea

我有一个有两列的数据框。我正在尝试使用以下说明添加新的空列:

df['new_col'] = ''
已添加列,但带有警告:

<ipython-input-16-779f11834aea>: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

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
:1:设置为带有CopyWarning:
试图在数据帧切片的副本上设置值。
尝试改用.loc[row\u indexer,col\u indexer]=value
请参阅文档中的注意事项:https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view vs-a-copy
我到底做错了什么?为什么会触发此警告

提前感谢

使用

df=df.assign(new_col = '')