[英]Convert dataframe column into binary
My crm
data frame contains a column "Reconciled" with numbers from 0 to 130.我的crm
数据框包含一列“已协调”,数字从 0 到 130。
I want to convert this column into 0 or 1. If the value is 0, keep 0, otherwise change to 1.我想把这列转成0或1,如果值为0就保持0,否则改成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
Hera are alternatives for binary: Hera 是二进制的替代品:
crm['Reconciled'] = (crm['Reconciled'] > 0).astype(int)
crm['Reconciled'] = (crm['Reconciled'] > 0).view('i1')
crm['Reconciled'] = np.where(crm['Reconciled'] > 0, 1, 0)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.