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_nunique = list(map(lambda col: train_data[col].nunique(), object_cols))
d = dict(zip(object_cols, object_nunique))
object_nunique_test = list(map(lambda col: test_data[col].nunique(), test_object_cols))
d_test = dict(zip(test_object_cols, object_nunique_test))
sorted(d.items(), key=lambda x: x[1])

sorted(d.items(), key=lambda x: x[1])