text_plain_output_1.png
from plotly.subplots import make_subplots

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import plotly.graph_objects as go

train = pd.read_csv('/kaggle/input/spaceship-titanic/train.csv')
test = pd.read_csv('/kaggle/input/spaceship-titanic/test.csv')
submission = pd.read_csv('/kaggle/input/spaceship-titanic/sample_submission.csv')
RANDOM_STATE = 12
FOLDS = 5
STRATEGY = 'median'

train.drop(['PassengerId'], axis=1, inplace=True)
test.drop(['PassengerId'], axis=1, inplace=True)
TARGET = 'Transported'
FEATURES = [col for col in train.columns if col != TARGET]
RANDOM_STATE = 12

test_null = pd.DataFrame(test.isna().sum())
test_null = test_null.sort_values(by = 0 ,ascending = False)
# test data의 null값들을 뽑아서 값을 정렬한다.
train_null = pd.DataFrame(train.isna().sum())
train_null = train_null.sort_values(by = 0 ,ascending = False)[:-1]
# train data의 null값들을 뽑아서 값을 정렬한다.

# subplots를 활용해서 그래프 2개를 나란히 출력할수 있게 한다.
fig = make_subplots(rows=1, 
                    cols=2,
                    column_titles = ["Train Data", "Test Data"] ,
                    x_title="Missing Values")

# 각각 그래프 추가
fig.add_trace(go.Bar(x=train_null[0],
                     y=train_null.index,
                     orientation="h",
                    marker=dict(color=[n for n in range(12)], 
                                line_color='rgb(0,0,0)' , 
                                line_width = 2,
                                coloraxis="coloraxis")),
              1, 1)

# 각각 그래프 추가
fig.add_trace(go.Bar(x=test_null[0], 
                     y=test_null.index,
                     orientation="h",
                    marker=dict(color=[n for n in range(12)], 
                                line_color='rgb(0,0,0)', 
                                line_width = 2,
                                coloraxis="coloraxis")),
              1, 2)

fig.update_layout(showlegend=False, title_text="Column wise Null Value Distribution", title_x=0.5)

missing_train_row = train.isna().sum(axis=1)
missing_train_row = pd.DataFrame(missing_train_row.value_counts() / train.shape[0]).reset_index()
missing_test_row = test.isna().sum(axis=1)
missing_test_row = pd.DataFrame(missing_test_row.value_counts() / test.shape[0]).reset_index()
missing_train_row.columns = ['no', 'count']
missing_test_row.columns = ['no', 'count']
missing_train_row['count'] = missing_train_row['count'] * 100
missing_test_row['count'] = missing_test_row['count'] * 100
fig = make_subplots(rows=1, cols=2, column_titles=['Train Data', 'Test Data'], x_title='Missing Values')
fig.add_trace(go.Bar(x=missing_train_row['no'], y=missing_train_row['count'], marker=dict(color=[n for n in range(4)], line_color='rgb(0,0,0)', line_width=3, coloraxis='coloraxis')), 1, 1)
fig.add_trace(go.Bar(x=missing_test_row['no'], y=missing_test_row['count'], marker=dict(color=[n for n in range(4)], line_color='rgb(0,0,0)', line_width=3, coloraxis='coloraxis')), 1, 2)
fig.update_layout(showlegend=False, title_text='Row wise Null Value Distribution', title_x=0.5)