我收到SettingWithCopyWarning,表明我可能存在链接问题。
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
我已经详细阅读了此内容,但似乎无法找到适合我的用例的正确解决方案。这是一篇关于该主题的精彩文章:Understanding SettingwithCopyWarning in pandas
但是,我仍然不太确定如何继续。以下是同一行代码的三个变体,它们产生最终结果,但都会抛出相同的错误。
变化:
X[subindex + '_DE'] = X[subindex + '_DE'].clip(lower=0, upper=200, axis=0)
X.loc[:, subindex + '_DE'] = np.clip(df.loc[:, subindex + '_DE'], 0, 200)
X.loc[:, subindex + '_DE'] = X.loc[:, subindex + '_DE'].clip(lower=0, upper=200, axis=0)
最终目标:简单地剪切(截断)列 [subindex + '_DE'] 中超出下限 (0) 和上限 (200) 的任何值。
我不知道如何继续。一点指导会有所帮助。预先感谢您。
有用的背景信息:
X 是 float64 数据的 pandas 数据框,排列为 20 列(特征)x 6514 行(观察)。
这里有一些可以使用的数据:
> print(X[subindex + '_DE'].head(180))
> date
> 1999-12-31 33.6584
> 2000-01-01 33.6584
> 2000-01-02 33.6584
> 2000-01-03 33.6584
> ... ...
> 2000-06-25 32.6530
> 2000-06-26 32.6530
> 2000-06-27 32.6530
> Name: NYEPLC_DE, Length: 180, dtype: float64
最佳答案
找到了答案。
在 def
中,我设置了 X = df[]
(数据帧)。如果我只是将 .copy()
添加到 df[]
,那么警告就会消失。
例如X = df[['column1', 'column2']].copy()
上面 Benjamin Pryke 的文章非常好......
关于python - 设置复制警告和隐藏链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47395944/