filmov
tv
Pandas: Converting Categorical Columns to Numerical #datascience #python #pandas #machinelearning
Показать описание
In this short, I show you a function I wrote to prepare pandas data frames for machine learning models.
Here's the function:
def cat2num(dataframe):
if dataframe[column].dtype == 'object':
dataframe[column] = pd.Categorical(dataframe[column]).codes
return dataframe
Here's the function:
def cat2num(dataframe):
if dataframe[column].dtype == 'object':
dataframe[column] = pd.Categorical(dataframe[column]).codes
return dataframe