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

df_train = pd.read_csv('/kaggle/input/santander-customer-satisfaction/train.csv')

df_test = pd.read_csv('/kaggle/input/santander-customer-satisfaction/test.csv')

df_merge = pd.concat([df_test.assign(ind='test'), df_train.assign(ind='train')])

df_merge.shape

cat_cols = [cname for cname in df_merge.columns if df_merge[cname].dtype == 'object']

num_cols = [cname for cname in df_merge.columns if df_merge[cname].dtype != 'object']

test, train = (df_merge[df_merge['ind'].eq('test')], df_merge[df_merge['ind'].eq('train')])
test.drop(['TARGET', 'ind'], axis=1, inplace=True)
train.drop(['ind'], axis=1, inplace=True)

from sklearn.feature_selection import VarianceThreshold as VT
var_thres = VT(threshold=0)
var_thres.fit(X_train)

const_cols = [col for col in X_train.columns if col not in X_train.columns[var_thres.get_support()]]

X_train.drop(columns=const_cols, axis=1, inplace=True)
X_valid.drop(columns=const_cols, axis=1, inplace=True)
test.drop(columns=const_cols, axis=1, inplace=True)

(X_train.shape, X_valid.shape, test.shape)