how to change int to Binary value

Advertisements

Hi everyone I have a problem to change 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 :

enter image description here

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 doesnt work

Will anyone able to run that? Any ideas?What could be causing this issue?

Thanks!

>Solution :

Use

Dt["new_cases"] = Dt["new_cases"].apply(lambda x: 1 if x >= 1 else 0)

OR

Dt["new_cases"] = 1
Dt.loc[Dt["new_cases"] < 1, "new_cases"] = 0

Leave a ReplyCancel reply