Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
79 views
in Technique[技术] by (71.8m points)

python - could not convert string to float: 'Runny_nose'

import pandas as pd
from sklearn.tree import DecisionTreeClassifier

Disease_data = pd.read_csv("Disease_dataset.csv")

X = Disease_data.drop(columns='Diseases')
y = Disease_data['Diseases']

model = DecisionTreeClassifier() 
model.fit(X, y)

I get this error:

ValueError: could not convert string to float: 'Runny_nose'

I tried

Disease_data = Disease_data['Diseases'].astype(float)

and

music_data = pd.to_numeric(music_data, errors='coerce')

instead I get empty columns

question from:https://stackoverflow.com/questions/65867768/could-not-convert-string-to-float-runny-nose

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The error is pretty clear: ValueError: could not convert string to float: 'Runny_nose'.

The Diseases column in Disease_data['Diseases'] is of string type (I assume based on it's name) and you are trying to convert it to float and hence the error.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

Just Browsing Browsing

[4] html - How to create even cell spacing within a

2.1m questions

2.1m answers

60 comments

57.0k users

...