[英]Converting float64 to 1 as int, naan to 0 as int
I am predicting loans, and have a column with number of months since last delinquency.我正在预测贷款,并且有一列自上次拖欠以来的月数。 There are many missing values because many people are not delinquent.
有很多缺失值,因为很多人没有违法。 I cannot fill in zeros, as that would mean they were delinquent.
我不能填零,因为那意味着他们是拖欠的。 I would like to convert any numeric values to '1', and any Naan to '0'.
我想将任何数值转换为“1”,将任何 Naan 转换为“0”。 The column is a float64.
该列是一个 float64。
I have tried converting float64 to int(), train['X25'] = int(train['X25'])
but got TypeError: cannot convert the series to <class 'int'>我尝试将 float64 转换为 int(),
train['X25'] = int(train['X25'])
但得到 TypeError: cannot convert the series to <class 'int'>
What it looks like它看起来像什么
Loan Number Months Since Delinquency
1 Naan
2 0
3 3
What I want it to look like我希望它看起来像什么
Loan Delinquency
1 0
2 1
3 1
您应该使用df['Delinquency '] = df['Months Since Delinquency'].isna()
来获取布尔列
这应该工作
df['Delinquency'] = df['Months Since Delinquency'].notnull().astype(int)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.