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
Asked
Active
Viewed 459 times
0
-
Hi, perhaps use `DataFrame.replace` https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.replace.html – IronMan Oct 08 '20 at 22:54
-
1Does this answer your question? [Replacing column values in a pandas DataFrame](https://stackoverflow.com/questions/23307301/replacing-column-values-in-a-pandas-dataframe) – Anurag Reddy Oct 08 '20 at 23:25
1 Answers
1
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

MECoskun
- 789
- 6
- 12
-
1Series.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})` – Cameron Riddell Oct 08 '20 at 23:28