1

Consider a column(Result) in a data frame df which is stored with 0's and 1's.

0 indicates Fail and 1 indicates Pass.

How do I replace 0's with Fail and 1's with Pass for df['Result'] column?

Aneesha
  • 25
  • 4

2 Answers2

1

Us pandas.Series.map:

df.results = df.results.map({0: 'Fail', 1: 'Pass'})
Ami Tavory
  • 71,268
  • 10
  • 134
  • 170
0

You can try with:

df['Result'] = np.where(df['Result'] == 0, 'Fail', 'Pass')
Joe
  • 11,147
  • 5
  • 36
  • 50
moys
  • 7,302
  • 2
  • 7
  • 28