在处理来自 csv 文件的以下列的缺失数据时,它会引发 TypeError.How to resolve this?
trainData.Gender.fillna(trainData.Gender.max(),inplace =True)
trainData.Married.fillna(trainData.Married.max(),inplace=True)
TypeError: '>=' not supported between instances of 'str' and 'float'
trainData.dtypes
Loan_ID object
Gender object
Married object
Dependents object
Education object
Self_Employed object
ApplicantIncome int64
CoapplicantIncome float64
LoanAmount float64
Loan_Amount_Term float64
Credit_History float64
Property_Area object
Loan_Status object
最佳答案
这样做你实际上是在考虑丢失的数据(NaN,被视为浮点数)来寻找最大值。所以:
trainData.Gender.fillna(trainData.Gender.max(),inplace =True)
将尝试比较 str 与浮点数。
你需要做:
trainData.Gender.fillna(trainData.Gender.dropna().max(),inplace =True)
trainData.Gender.fillna(trainData.Married.dropna().max(),inplace =True)