kern
kern

Reputation: 135

How to convert column that has text element to column of numerics before modelling

I am working on a dataset that has
columns with text in it
How can I change Elements and Area with numbers before modelling

Upvotes: 0

Views: 18

Answers (1)

jezrael
jezrael

Reputation: 862431

If need factorize for strings columns use:

cols = df.select_dtypes(object).columns
df[cols] = df[cols].apply(lambda x: pd.factorize(x)[0])

Upvotes: 1

Related Questions