這裏是代碼,其中「LoanAmount」,「ApplicantIncome」,「CoapplicantIncome」是類型對象:對於大熊貓數據幀列中,類型錯誤:浮子()參數必須是字符串或數字
document=pandas.read_csv("C:/Users/User/Documents/train_u6lujuX_CVtuZ9i.csv")
document.isnull().any()
document = document.fillna(lambda x: x.median())
for col in ['LoanAmount', 'ApplicantIncome', 'CoapplicantIncome']:
document[col]=document[col].astype(float)
document['LoanAmount_log'] = np.log(document['LoanAmount'])
document['TotalIncome'] = document['ApplicantIncome'] + document['CoapplicantIncome']
document['TotalIncome_log'] = np.log(document['TotalIncome'])
我得到以下錯誤在轉換對象類型爲float:
TypeError: float() argument must be a string or a number
請幫助,因爲我需要通過這些功能來訓練我的分類模型。這裏的CSV文件的一個片段 -
Loan_ID Gender Married Dependents Education Self_Employed ApplicantIncome CoapplicantIncome LoanAmount Loan_Amount_Term Credit_History Property_Area Loan_Status
LP001002 Male No 0 Graduate No 5849 0 360 1 Urban Y
LP001003 Male Yes 1 Graduate No 4583 1508 128 360 1 Rural N
LP001005 Male Yes 0 Graduate Yes 3000 0 66 360 1 Urban Y
LP001006 Male Yes 0 Not Graduate No 2583 2358 120 360 1 Urban Y
可以添加CSV文件的片段?並添加了錯誤 – Dark
的行號! @Bharathshetty –
@Bharathshetty錯誤是在訓練數據在分類器 –