0
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

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

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

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy

K.zaid
  • 13
  • 2
  • you can find the clear details about this concept here. https://stackoverflow.com/questions/20625582/how-to-deal-with-settingwithcopywarning-in-pandas – Divya Bojanpalli Oct 01 '20 at 08:23

2 Answers2

0

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.

Edit 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. Instead of your top three lines, I suggest you use:

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

Here you go :

import warnings
warnings.filterwarnings("ignore")