-1

Have marked the current Df and the expected output. I would like to add a new column "Rank" based on the values of "Score" with the conditions as IF SCORE>=80,"EXP", ELSE IF SCORE<=34,"FAIL",ELSE,"PASS"

Request guidance.

Current and expected results:

xxx

martineau
  • 119,623
  • 25
  • 170
  • 301
Dhriti
  • 3
  • 1
  • please, don't post images of code, input, output, errors. Copy/paste here as text. see [ask]. – buran Jan 17 '21 at 19:07
  • I suggest you improve your question, add some examples, some code and make it more clear what you want to achieve. Have a look here => [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) – Federico Baù Jan 17 '21 at 19:14
  • check out this: https://stackoverflow.com/questions/39109045/numpy-where-with-multiple-conditions – sophocles Jan 17 '21 at 22:38

1 Answers1

1

Create the DataFrame:

df = pd.DataFrame({'Name':['a','b','c','d','e','f'],
                   'Score':[65,75,85,35,20,34]})

Then add a new column RANK with the condition you asked:

df['Rank'] = ['EXP' if i>=85 else 'FAIL' if i<=34  else 'PASS' for i in df['Score']]

Result:

print(df)

  Name  Score  Rank
0    a     65  PASS
1    b     75  PASS
2    c     85   EXP
3    d     35  PASS
4    e     20  FAIL
5    f     34  FAIL
gioarma
  • 418
  • 2
  • 15