简体   繁体   English

如何删除此警告消息?

[英]how do I remove this warning message?

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: A value is trying to be set on a copy of a slice from a DataFrame C:\\Users\\Admin\\anaconda3\\lib\\site-packages\\ipykernel_launcher.py:7: SettingWithCopyWarning: 试图在 DataFrame 的切片副本上设置值

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy import sys C:\\Users\\Admin\\anaconda3\\lib\\site-packages\\pandas\\core\\generic.py:8767: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame请参阅文档中的警告: https : //pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy import sys C:\\Users\\Admin\\anaconda3 \\lib\\site-packages\\pandas\\core\\generic.py:8767: SettingWithCopyWarning: 试图在 DataFrame 的切片副本上设置值

See the caveats in the documentation: 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: A value is trying to be set on a copy of a slice from a 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 的切片副本上设置值

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

We could do with seeing your code, but assuming you are filtering or slicing a dataframe, you can use .copy() to take a hard copy of the df in question which should negate that error.我们可以查看您的代码,但假设您正在过滤或切片数据帧,您可以使用.copy()获取有问题的 df 的硬拷贝,这应该可以消除该错误。

Edit 1:编辑1:

I can see that you are trying to rename rain/snow in the "precip_type" column, but not actually using the dictionary you have created.我可以看到您正在尝试在“precip_type”列中重命​​名rain/snow,但实际上并未使用您创建的字典。 Instead of your top three lines, I suggest you use:而不是你的前三行,我建议你使用:

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

Here you go :干得好 :

import warnings
warnings.filterwarnings("ignore")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM