如何解决(settingWithCopyWarning:正在尝试从DataFrame的切片副本上设置一个值。)?

时间:2020-08-16 03:48:27

标签: python pandas dataframe

这是我的代码,用于在数据框中创建带有计算的新列

df1['Cases/Tests/1M pop']= (df1['Tot Cases/1M pop']/ df1['Tests/ 1M pop'])*100

我在输出中得到了此错误消息

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
 df1['Cases/Tests/1M pop']= (df1['Tot Cases/1M pop']/ df1['Tests/ 1M pop'])*100

0 个答案:

没有答案