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
  • 5

2 Answers2

1

Us pandas.Series.map:

df.results = df.results.map({0: 'Fail', 1: 'Pass'})
Ami Tavory
  • 74,578
  • 11
  • 141
  • 185
0

You can try with:

df['Result'] = np.where(df['Result'] == 0, 'Fail', 'Pass')
Joe
  • 12,057
  • 5
  • 39
  • 55
moys
  • 7,747
  • 2
  • 11
  • 42