Home > Blockchain >  how to change int to Binary value
how to change int to Binary value

Time:12-18

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!

CodePudding user response:

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

CodePudding user response:

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
  • Related