-1

Here's my data

Id  WO
1   56
2   23
3    0  

My rule is simple, if WO at least 1 give label 1, if less give 0, here's my expected output

Id  WO  Label
1   56  1
2   23  1
3    0  0  

Here's my code

import math
due_table_2['Label'] = due_table_2.apply(math.ceil(due_table_2['WO ']/1000))

the error message

TypeError: cannot convert the series to <class 'float'>

Nabih Bawazir
  • 6,381
  • 7
  • 37
  • 70
  • Does this answer your question? [numpy.where() detailed, step-by-step explanation / examples](https://stackoverflow.com/questions/34667282/numpy-where-detailed-step-by-step-explanation-examples) – wwnde May 04 '21 at 04:39

1 Answers1

0

Problem is that math.ceil() doesn't accept Series type variable. You can use np.where()

due_table_2['Label'] = np.where(due_table_2['WO '] >= 1, 1, 0)

Or just convert boolean to int with

due_table_2['Lable'] = (due_table_2['WO '] >= 1).astype(int)
Ynjxsjmh
  • 28,441
  • 6
  • 34
  • 52