python - Why does Pandas give me only one SettingWithCopyWarning? -
i have following code:
import pandas pd import numpy np mydf = pd.dataframe({'uid':[1,2,3], 'price':[10,20,30], 'shipped':[2,4,6]}) grouped = mydf.groupby('uid').aggregate(np.sum) # call 1 mydf['price'].loc[:] = np.round(grouped['price'], 2) # call 2 mydf['shipped'].loc[:] = grouped['shipped']
the line have preceded call 1
executes no errors or warnings. line have preceded call 2
results in settingwithcopywarning
error. why 1 result in error , not other? can in second call in order rid of error?
my code executes fine, i'm tired on seeing 1 lone error every time run tests.
no settingwithcopywarning error
mydf['shipped'].values[:] = grouped['shipped']
Comments
Post a Comment