-4

Could you please help me generating third column from the table using Python? I tried with numpy.where option, but I am unable to get the desired output.

My table:

my table

I have tried the code

 db['Condition'] = numpy.where(db.Value <50, 'Less than 50', db.Value <100, 'Less than 100','more than 100'). 

Here, db refers to data base name. And the error message I am getting

TypeError: where() takes at most 3 arguments (5 given)

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Kamesh
  • 9
  • 4
  • 2
    Please provide [MCVE](https://stackoverflow.com/help/mcve) and show your current attempt and error messages. – Dodge Nov 22 '18 at 16:44
  • Hi, Thanking you very much for the comment. I have tried the code db['Condition'] = numpy.where(db.Value <50, 'Less than 50', db.Value <100, 'Less than 100','more than 100'). Here, db refers to data base name. And the error message I am getting TypeError: where() takes at most 3 arguments (5 given) – Kamesh Nov 22 '18 at 17:04

1 Answers1

0

According to numpy.where documentation, it only takes 3 arguments, condition and x (if true),y (if false) array_like. To get your desired output:

db['Condition'] = numpy.where(db['Value'] < 50, 'Less than 50', numpy.where(db['Value']<100, 'Less than 100','More than 100'))
Ricky Kim
  • 1,992
  • 1
  • 9
  • 18