text_html_output_1.png
import pandas as pd

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

train[['Deck', 'Cabin_Num', 'Side']] = train.Cabin.str.split('/', expand=True)
test[['Deck', 'Cabin_Num', 'Side']] = test.Cabin.str.split('/', expand=True)

train[['Group', 'Group_Num']] = train.PassengerId.str.split('_', expand=True)
test[['Group', 'Group_Num']] = test.PassengerId.str.split('_', expand=True)

mode_list = ['HomePlanet', 'CryoSleep', 'Destination', 'VIP', 'Deck', 'Side']
for i in mode_list:
    train[i] = train[i].fillna(train[i].mode()[0])
    test[i] = test[i].fillna(train[i].mode()[0])

median_list = ['Age', 'RoomService', 'FoodCourt', 'ShoppingMall', 'Spa', 'VRDeck']
for i in median_list:
    train[i] = train[i].fillna(train[i].median())
    test[i] = test[i].fillna(train[i].median())
for i in train.columns:
    if train[i].isna().sum() > 0:
        print(f'{i}: {train[i].isna().sum()}')