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

Convert dataframe column into binary

My crm data frame contains a column "Reconciled" with numbers from 0 to 130.

I want to convert this column into 0 or 1.
If the value is 0, keep 0, otherwise change to 1.

crm['Reconciled'] = crm['Reconciled'].where(crm['Reconciled'] > 0, 1)

Now:

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

crm['Reconciled'].describe()

Returns:

count     138234
unique         1
top            1
freq      138234
Name: Reconciled, dtype: int64

>Solution :

Hera are alternatives for binary:

crm['Reconciled'] = (crm['Reconciled'] > 0).astype(int)
crm['Reconciled'] = (crm['Reconciled'] > 0).view('i1')
crm['Reconciled'] = np.where(crm['Reconciled'] > 0, 1, 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