I working with DataFrames a lot and sometimes I need to replace values of whole column to another.
Usually I got a SettingWithCopyWarning
. So if I got it i just copy my df and work is progressing.
Example:
df
name male
sd Female
as Male
we Female
dd Female
df = df.copy()
df['male'] = df['male'].replace({'Female':'F', 'Male':'M'})
result:
df
name male
sd F
as M
we F
dd F
So I copied my frame and changing values on copy. If I understand good I copy a frame. So I using 2x memory? And even If I omit df = df.copy()
my code work fine but I got error info. Output still is ok.
So... I didn't found clear enough explanation, so I'm asking here. Is a good practice to copy my frames? Maybe is a different, better way?