text_html_output_1.png
from sklearn.impute import KNNImputer

from sklearn.preprocessing import LabelEncoder

import pandas as pd

import seaborn as sns

df = pd.read_csv('../input/spaceship-titanic/train.csv')

df.sample(5)

df.shape

round(df.isna().sum() / df.shape[0] * 100, 2)

df.drop(['PassengerId', 'Cabin', 'Name'], axis=1, inplace=True)
df.Transported = df.Transported.astype('str')

le = LabelEncoder()
for col in df.select_dtypes(include='object'):
    df[col] = le.fit_transform(df[col])

KNNImpute = KNNImputer()
newdf = KNNImpute.fit_transform(df)
df = pd.DataFrame(newdf, columns=df.columns)

df.describe()