0

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

  • 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
  • 1
    Does 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 Answers1

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
  • 1
    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})` – Cameron Riddell Oct 08 '20 at 23:28