Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to change int to Binary value

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading