text_html_output_1.png
import numpy as np # linear algebra

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

training = pd.read_csv('../input/tabular-playground-series-aug-2022/train.csv')

training.fillna(0)

cat_cols = [col for col in training.columns if training[col].dtype == 'object']
cat_cols

training = training[cat_cols + ['failure']]
training

woe = pd.crosstab(training['product_code'], training['failure'])
woe['sum'] = woe[0] + woe[1]
woe['%0'] = woe[0] / woe[0].sum()
woe['%1'] = woe[1] / woe[1].sum()
woe['woe'] = np.log(woe['%1'] / woe['%0'])
woe