image_output_1.png
import numpy as np

import pandas as pd

traindf = pd.read_csv('/kaggle/input/spaceship-titanic/train.csv')
testdf = pd.read_csv('/kaggle/input/spaceship-titanic/test.csv')
data_cleaner = [traindf, testdf]

traindf.shape

traindf.columns

traindf['Expenses_group'] = np.nan
traindf.loc[traindf['totalExpenses'] == 0, 'Expenses_group'] = 'Expenses_0'
traindf.loc[(traindf['totalExpenses'] > 0) & (traindf['totalExpenses'] <= 500), 'Expenses_group'] = 'Expenses_0-500'
traindf.loc[(traindf['totalExpenses'] > 500) & (traindf['totalExpenses'] <= 1000), 'Expenses_group'] = 'Expenses_500-1000'
traindf.loc[(traindf['totalExpenses'] > 1000) & (traindf['totalExpenses'] <= 5000), 'Expenses_group'] = 'Expenses_1000-5000'
traindf.loc[(traindf['totalExpenses'] > 5000) & (traindf['totalExpenses'] <= 500000000000), 'Expenses_group'] = 'Expenses_5000+'
testdf['Expenses_group'] = np.nan
testdf.loc[testdf['totalExpenses'] == 0, 'Expenses_group'] = 'Expenses_0'
testdf.loc[(testdf['totalExpenses'] > 0) & (testdf['totalExpenses'] <= 500), 'Expenses_group'] = 'Expenses_0-500'
testdf.loc[(testdf['totalExpenses'] > 500) & (testdf['totalExpenses'] <= 1000), 'Expenses_group'] = 'Expenses_500-1000'
testdf.loc[(testdf['totalExpenses'] > 1000) & (testdf['totalExpenses'] <= 5000), 'Expenses_group'] = 'Expenses_1000-5000'
testdf.loc[(testdf['totalExpenses'] > 5000) & (testdf['totalExpenses'] <= 500000000000), 'Expenses_group'] = 'Expenses_5000+'

print(traindf.loc[traindf.totalExpenses > 0, 'totalExpenses'].count(), traindf.loc[traindf.totalExpenses == 0, 'totalExpenses'].count())