i wanted to to replace the yes and no values in No-show column to be changed to 0 and 1 valuesenter image description here
1 Answer
Here is a simple answer:
df = pd.DataFrame({'No-show':['Yes','No','No','Yes']})
df['No-show'] = df['No-show'].replace('Yes',1).replace('No',0)
df
output:
No-show
0 1
1 0
2 0
3 1
1 Comment
Cameron Riddell
Series.replace also accepts a dictionary so you don't need to call it twice:
df['No-show'] = df['No-show'].replace({"Yes": 1, "No": 0})
DataFrame.replacepandas.pydata.org/pandas-docs/stable/reference/api/…