使用SettingWithCopyWarning,有时它会指向您模块中触发警告的确切代码行(例如此处),而其他时候则不会(例如此处)。
没有遍历代码的每一行(如果您正在查看数百行代码,这听起来不太吸引人),是否有一种方法可以确定触发警告的代码行,前提是警告没有返回该信息?
我想知道这是否是警告中的一个错误,即返回警告而没有查明触发它的特定代码。
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
Run Code Online (Sandbox Code Playgroud)
Python 3.4,熊猫 0.15.0
您可以通过将选项设置为SettingWithCopyError而不是 来让pandas raise而不是。SettingWithCopyWarningmode.chained_assignmentraisewarn
import pandas as pd
pd.set_option('mode.chained_assignment', 'raise')
Run Code Online (Sandbox Code Playgroud)
https://pandas.pydata.org/pandas-docs/stable/options.html#available-options
| 归档时间: |
|
| 查看次数: |
855 次 |
| 最近记录: |