Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

not supported between instances of 'str' and 'float'

While handling with missing data for below columns from csv file it throws 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
like image 667
user63827 Avatar asked Dec 07 '22 18:12

user63827


1 Answers

Doing it that way you are actually considering missing data(NaN, which are treated as floats) to look for the maximum value. So:

trainData.Gender.fillna(trainData.Gender.max(),inplace =True)

will try to compare str vs. floats.

You need to do:

trainData.Gender.fillna(trainData.Gender.dropna().max(),inplace =True)
trainData.Gender.fillna(trainData.Married.dropna().max(),inplace =True)
like image 191
VictorGGl Avatar answered Jan 08 '23 15:01

VictorGGl