how to change value in pandas dataframe code example
Example 1: replacing values in pandas dataframe
df['coloum'] = df['coloum'].replace(['value_1','valu_2'],'new_value')
Example 2: replace multiple values in pandas column
df = pd.DataFrame({'a':['Small', 'Medium', 'High']})
In [22]: df
Out[22]:
a
0 Small
1 Medium
2 High
[3 rows x 1 columns]
df.replace({'a' : { 'Medium' : 2, 'Small' : 1, 'High' : 3 }})
Example 3: column.replace
df.column = df.coloumn.replace('old_value', 'new_value')