in one of the columns in my dataframe I have five values:
1,G,2,3,4
How to make it change the name of all "G" to 1
I tried:
df = df['col_name'].replace({'G': 1})
I also tried:
df = df['col_name'].replace('G',1)
"G" is in fact 1 (I do not know why there is a mixed naming)
Edit:
works correctly with:
df['col_name'] = df['col_name'].replace({'G': 1})
df['col_name'].replace({'G': 1})is the right (a right) thing to do. You just need to assign it back to the dataframe appropriately.df['col_name'] = df['col_name'].replace({'G': 1})ORdf.update(df['col_name'].replace({'G': 1}))ORdf = df.assign(col_name=df['col_name'].replace({'G': 1}))