【问题标题】:Getting SettingWithCopyWarning when applying apply on a DataFrame Pandas在 DataFrame Pandas 上应用应用时获取 SettingWithCopyWarning
【发布时间】:2018-12-25 05:53:33
【问题描述】:

我不断收到此警告,但真的不知道我应该在这里更改什么:

C:\Users\3626416\Software\Anaconda\lib\site-packages\pandas\core\indexing.py:543:
    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

请参阅文档中的注意事项:
http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy

self.obj[item] = s

这是我的代码:

df_pcl.loc[:,['Weight','Pieces','Cons','DeadWeight']] = df_pcl.loc[:,['Weight','Pieces','Cons','DeadWeight']] * pcl2docRtio

【问题讨论】:

    标签: python pandas dataframe


    【解决方案1】:

    我找到了根本原因。必须使用 df_pcl = source_df.loc[idx,:].copy() 而不是 df_pcl = source_df.loc[idx,:]。

    【讨论】:

      猜你喜欢
      • 2016-10-16
      • 2022-10-04
      • 2017-11-14
      • 2016-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-16
      • 1970-01-01
      相关资源
      最近更新 更多