I have code as below.i get bunch of SettingWithCopyWarning
messages. But if i check 3 dataframes after the last statement, only df_numeric['class']
has value 99. In other two dataframes class
value remains unchanged. WHy? i thought that due to SettingWithCopyWarning
, after the last statement class
values in all dataframe would change
please explain what is going on
import pandas as pd
import numpy as np
data = [['Alex',10,5,0],['Bob',12,4,1],['Clarke',13,6,0],['brke',15,1,0]]
df = pd.DataFrame(data,columns=['Name','Age','weight','class'],dtype=float)
df_numeric=df.select_dtypes(include='number')#, exclude=None)[source]
df_non_numeric=df.select_dtypes(exclude='number')
df_non_numeric['class']=df_numeric['class'].copy()
df_numeric['class']=99