KitDocumentation

ColumnCast

Casts the datatype of one or more columns to another type to modidy how python / pandas interprets the column's data. The columns can be cast to either an int, float, string, bool, datetime, or category.

Options

columns: ColumnName(s) to be cast, either a single column or a list of columns.
type: The specific data type to cast to, such as int, float, string, bool, datetime, category

Examples

Example 1 - Cast Single Column

Our rating was initially a decimal number, but we would rather it be an integer. We cast the Rating column to an integer to remove the decimal values.
#> ColumnCast Rating --type int
AFLEFT 
pizzeriasDf['Rating'] = pizzeriasDf['Rating'].astype('int') AFRIGHT

Example 2 - Cast Multiple Columns

Rather than casting a single columns, cast multiple columns to a data type simply by specifying multiiple column names.
#> ColumnCast Specialty Pizza Established Year --type string
AFLEFT 
pizzeriasDf['Specialty Pizza'] = pizzeriasDf['Specialty Pizza'].astype('str')
pizzeriasDf['Established Year'] = pizzeriasDf['Established Year'].astype('str') AFRIGHT