Search code examples
pythonsymbolic-math

how to change int to Binary value


I have a problem changing my data into binary. It's not so complicated just using basic math; like if a = 60, then the result is "good", and when a >= 60, then it is "very good", but this is implemented in the data below:

Screenshot

This is my data; I want to change new_cases data to be binary value when the data >=1; I want the result to be 1, but when I use

Dt[Dt['new_cases'] >= 1 ] = 1

It doesn't work.

Please, is anyone able to run it? Any ideas? What could be causing this issue?

Thanks!


Solution

  • You have to specify the column where you want to change the values: Dt.loc[Dt['new_cases'] >= 1, 'new_cases'] = 1