I see that similar questions have been asked, but it doesn't look like those were caused by the same problem. Here is my code that gives the error:
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.neighbors import KNeighborsClassifier
from sklearn.neighbors import KNeighborsRegressor
from io import StringIO
d = pd.read_csv("http://www.stat.wisc.edu/~jgillett/451/data/kaggle_titanic_train.csv")
data =d[['Survived','Pclass','Sex','Age','SibSp','Parch']]
#print(data.head(n=7))
y = data.Survived
X = data[['Pclass','Sex','Age','SibSp','Parch']]
k = 3
knn = KNeighborsClassifier(n_neighbors=k, weights='distance', metric='euclidean')
knn.fit(X, y)
So I tried to convert it to float like this:
data.Sex=data[['Sex']].astype(float)
But that just gives the exact same error. Why is it not able to convert the string to float?