Next, the counter of each column in the data frame will be printed if it is a subset of your CONT list.
CONT = ['age', 'fnlwgt', 'capital-gain', 'capital-loss']
df = pd.DataFrame(np.random.rand(5, 2), columns=CONT[:2])
>>> df
age fnlwgt
0 0.079796 0.736956
1 0.120187 0.778335
2 0.698782 0.691850
3 0.421074 0.369500
4 0.125983 0.454247
Select a subset of columns and do the conversion.
>>> df[[c for c in CONT if c in df]].count()
age 5
fnlwgt 5
dtype: int64
source
share