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

train_data = pd.read_csv('/kaggle/input/titanic/train.csv', index_col='PassengerId')

test_data = pd.read_csv('/kaggle/input/titanic/test.csv', index_col='PassengerId')

cols_with_missing = [col for col in train_data.columns if train_data[col].isnull().any()]
cols_with_missing

cat = train_data.dtypes == 'object'
object_cols = list(cat[cat].index)
object_cols

test_cols_with_missing = [col for col in test_data.columns if test_data[col].isnull().any()]
test_cols_with_missing

test_cat = test_data.dtypes == 'object'
test_object_cols = list(test_cat[test_cat].index)
test_object_cols

object_cols = [col for col in train_data.columns if train_data[col].dtype == 'object']
good_label_cols = [col for col in object_cols if set(train_data[col]) == set(test_data[col])]
bad_label_cols = list(set(object_cols) - set(good_label_cols))

cat = X_train.dtypes == 'object'
object_cols = list(cat[cat].index)
object_cols
object_cols = [col for col in X_train.columns if X_train[col].dtype == 'object']
good_label_cols = [col for col in object_cols if set(X_train[col]) == set(X_valid[col])]
bad_label_cols = list(set(object_cols) - set(good_label_cols))
print('Categorical columns that will be label encoded:', good_label_cols)
print('\nCategorical columns that will be dropped from the dataset:', bad_label_cols)