Home > database >  Convert dataframe column into binary
Convert dataframe column into binary

Time:11-17

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:

crm['Reconciled'].describe()

Returns:

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

CodePudding user response:

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