gpt4 book ai didi

python - Pandas:SettingWithCopyWarning 触发位置

转载 作者:太空宇宙 更新时间:2023-11-03 12:07:02 25 4
gpt4 key购买 nike

使用 SettingWithCopyWarning,有时它会指向您模块中触发警告的确切代码行(例如 here ),有时则不会(例如 here )。

没有遍历每一行代码(如果你正在审查数百行代码,这听起来不太吸引人),有没有办法查明触发警告的代码行,假设警告没有返回该信息?

我想知道这是否是警告中的一个错误,即在没有查明触发它的具体代码的情况下返回警告。

Warning (from warnings module):
File "C:\Python34\lib\site-packages\pandas\core\indexing.py", line 415
self.obj[item] = s
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 the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy

Python 3.4, Pandas 0.15.0

最佳答案

您可以通过将 mode.chained_assignment 选项设置为 raise 来让 pandas 引发 SettingWithCopyError 而不是 SettingWithCopyWarning 警告

import pandas as pd
pd.set_option('mode.chained_assignment', 'raise')

https://pandas.pydata.org/pandas-docs/stable/options.html#available-options

关于python - Pandas:SettingWithCopyWarning 触发位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27659384/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com