Encoder.standardize_categorical_cols

Standardize the given categorical columns into the same format. [source]
Parameters:
df : pandas.DataFrame
  A dataframe with categorical columns we wish to standardize.

cols : list
  A list with the columns to be standardized.
Returns:
df_st : pandas.DataFrame
  The Dataframe with the given columns standardized.
See also:
encoder.categorize_cols
 Divide continuous columns into categories.

encoder.encode_df
  Encode the given categorical columns into patterned strings.

Example:

# Imports
>>> from zgli.encoder import Encoder
>>> from sklearn import datasets

# Load Iris df
>>> iris = datasets.load_iris()
>>> iris_df = pd.DataFrame(iris['data'])

# Define iris df cols
>>> cols = [0,1,2,3]

# Divide iris df
>>> cuts = [4,4,4,4]
>>> encoder = Encoder()
>>> df_ct = encoder.categorize_cols(iris_df,cols,cuts)
>>> df_ct.head()
        0		1		2		3
0	(4.296, 5.2]	(3.2, 3.8]	(0.994, 2.475]	(0.0976, 0.7]
1	(4.296, 5.2]	(2.6, 3.2]	(0.994, 2.475]	(0.0976, 0.7]
2	(4.296, 5.2]	(2.6, 3.2]	(0.994, 2.475]	(0.0976, 0.7]
3	(4.296, 5.2]	(2.6, 3.2]	(0.994, 2.475]	(0.0976, 0.7]
4	(4.296, 5.2]	(3.2, 3.8]	(0.994, 2.475]	(0.0976, 0.7]

# Standardize df_div iris df
>>> df_std = encoder.standardize_categorical_cols(df_ct,cols) # We use the standardize function here.
>>> df_std.head()
0	1	2	3
0	0	2	0	0
1	0	1	0	0
2	0	1	0	0
3	0	1	0	0
4	0	2	0	0