Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 设置CopyWarning是否重要?_Python_Pandas - Fatal编程技术网

Python 设置CopyWarning是否重要?

Python 设置CopyWarning是否重要?,python,pandas,Python,Pandas,我按如下方式逐项向dataframe条目添加值: refined_cme_quandl_list['typical_daily_volume']= np.nan for index, row in refined_cme_quandl_list.iterrows(): refined_cme_quandl_list['typical_daily_volume'][index] = typical_volume[row['Quandl_download_symbol']] 我仍然得到了我

我按如下方式逐项向dataframe条目添加值:

refined_cme_quandl_list['typical_daily_volume']= np.nan
for index, row in refined_cme_quandl_list.iterrows():
    refined_cme_quandl_list['typical_daily_volume'][index] = typical_volume[row['Quandl_download_symbol']]
我仍然得到了我想要的,但我得到了以下警告:

SettingWithCopyWarning:正在尝试在副本上设置值 从数据帧切片

请参阅文档中的注意事项:


这有关系吗?

是的,不建议直接使用布尔索引分配给切片。改用
df.loc

refined_cme_quandl_list.loc[index, 'typical_daily_volume'] = \
                              typical_volume[row['Quandl_download_symbol']]

pandas的未来版本很可能会禁用这种行为(直接索引),因此您不希望将来的代码被破坏。

是的。您应该使用
.loc
分配到切片。您应该按照警告的建议“查看文档中的注意事项…”,并确定它在您的情况下是否重要。相关回答:完全正确。根据所使用的
numpy
python
(或其他
pandas
依赖项)的版本,行为甚至可能有所不同。因为文档中提到了使用CopyWarning抛出设置的代码:“除了简单的情况外,很难预测它将返回视图还是副本(这取决于数组的内存布局,pandas对此不作任何保证)”