[Solved] how to encode only categorical data in a dataframe


# Using standard scikit-learn label encoder.
from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()

# Encode all string columns. Assuming all categoricals are of type str.
for c in df.select_dtypes(['object']):
    print "Encoding column " + c
    df[c] = le.fit_transform(df[c])

3

solved how to encode only categorical data in a dataframe