text_plain_output_1.png
import pandas as pd

test = pd.read_csv('/kaggle/input/spaceship-titanic/test.csv')
test_pass_id = test.PassengerId.copy()

train = pd.read_csv('/kaggle/input/spaceship-titanic/train.csv')
train_pass_id = train.PassengerId.copy()

X = train.drop(columns='Transported')
y = train[['Transported']]

df = pd.concat([X, test], ignore_index=True)

nan_inicial = df.isna().sum()
nan_inicial

df[['deck', 'num', 'side']] = df['Cabin'].str.split(pat='/', expand=True)
df[['Passenger', '_Id']] = df['PassengerId'].str.split(pat='_', expand=True)
df[['Nome', 'Sobrenome']] = df['Name'].str.split(pat=' ', expand=True)
df.drop(columns=['Cabin', 'Name'], inplace=True)

df.replace({False: 0, True: 1}, inplace=True)

df.groupby(['HomePlanet']).deck.value_counts()

df.loc[df.deck == 'G', 'HomePlanet'] = 'Earth'
df.loc[(df.deck == 'T') | (df.deck == 'A') | (df.deck == 'B') | (df.deck == 'C'), 'HomePlanet'] = 'Europa'

df.groupby(['VIP']).deck.value_counts()

df.loc[(df.deck == 'G') | (df.deck == 'T'), 'VIP'] = 0

df.groupby(['CryoSleep']).deck.value_counts()

df.loc[df.deck == 'T', 'CryoSleep'] = 0

df.groupby(['CryoSleep', 'VIP']).agg({'RoomService': ['mean', 'min', 'max'], 'FoodCourt': ['mean', 'min', 'max'], 'ShoppingMall': ['mean', 'min', 'max'], 'Spa': ['mean', 'min', 'max'], 'VRDeck': ['mean', 'min', 'max']})