【问题标题】:how do I remove this warning message?如何删除此警告消息?
【发布时间】:2021-01-16 22:40:33
【问题描述】:
from sklearn.preprocessing import StandardScaler 
import numpy as np
import matplotlib.pyplot as mlt 
import seaborn as sb

precipitation = { 'rain': 0, 'snow': 1}
train['precip_type'][train['precip_type'] == 'rain'] =0
train['precip_type'][train['precip_type'] == 'snow'] =1 

stdsclr = StandardScaler() 
transf = stdsclr.fit_transform(train.values)
cov_mat = np.cov(transf.T)

mlt.figure(figsize=(12,12))
hm = sb.heatmap(cov_mat,
                 annot=True,
                 annot_kws={'size': 10},
                 cmap='coolwarm',                 
                 yticklabels=train.columns ,
                 xticklabels=train.columns)
mlt.show()

"""
there is insignificancy in wind_speed, cloud_cover, pressure and wind_bearing since they are not correlated
"""

C:\Users\Admin\anaconda3\lib\site-packages\ipykernel_launcher.py:7: SettingWithCopyWarning: 正在尝试在 DataFrame 中的切片副本上设置值

请参阅文档中的注意事项:https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy 导入系统 C:\Users\Admin\anaconda3\lib\site-packages\pandas\core\generic.py:8767: SettingWithCopyWarning: 正在尝试在 DataFrame 中的切片副本上设置值

请参阅文档中的注意事项:https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy self._update_inplace(new_data) C:\Users\Admin\anaconda3\lib\site-packages\ipykernel_launcher.py:8: SettingWithCopyWarning: 正在尝试在 DataFrame 中的切片副本上设置值

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

【问题讨论】:

标签: python warnings


【解决方案1】:

我们可以查看您的代码,但假设您正在过滤或切片数据帧,您可以使用 .copy() 获取相关 df 的硬拷贝,这应该可以消除该错误。

编辑 1:

我可以看到您正在尝试在“precip_type”列中重命​​名雨/雪,但实际上并未使用您创建的字典。我建议您不要使用前三行,而是使用:

precipitation = { 'rain': 0, 'snow': 1}
train = train.replace(precipitation)

【讨论】:

    【解决方案2】:

    给你:

    import warnings
    warnings.filterwarnings("ignore")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-25
      • 2015-06-28
      • 1970-01-01
      • 2010-12-31
      • 2011-08-08
      • 1970-01-01
      • 2018-01-06
      • 2018-12-22
      相关资源
      最近更新 更多