encode_income_binary

encode_income_binary(df, target_column='income')

Encode the income column of the Adult Census Income dataset into a binary target.

This function creates a binary target column where: - ‘<=50K’ is encoded as 0 - ‘>50K’ is encoded as 1

A new column named ‘income_binary’ is added to the returned DataFrame.

Parameters

Name Type Description Default
df pd.DataFrame The adult census income dataset found here in csv form: https://www.kaggle.com/datasets/uciml/adult-census-income required
target_column str Name of the income column to encode. 'income'

Returns

Name Type Description
pd.DataFrame A dataframe with an additional column called income_binary.

Raises

Name Type Description
TypeError If df is not a pandas DataFrame.
ValueError If target is not a column of df.

Examples

>>> encode_income_binary(adult_census_df)