我想将一列复制到新列中。 我使用以下代码:
df['income10']=df['income'].copy(deep=False)
我收到此错误:
/Users/hairy/ipykernel/ipykernel_launcher.py:2: 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: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
通过添加浅表副本,我认为我可以避免该错误。
答案 0 :(得分:1)
尝试这样做:
df['income10']=df.loc[:, ['income']]
答案 1 :(得分:0)
我重新运行了整个Jupyter笔记本,由于某些原因,它起作用了。