pythonpandasdataframenumpyone-hot-encoding

why is pd.get_dummies returning Boolean values instead of the binaries of 0 1


I don't know why my One-Hot encoding code; "pd.get_dummies" is returning Boolean values instead of the binaries of 0 1 df = pd.get_dummies(df)

after writing the following line of code; df = pd.get_dummies(df) and also tried; df = pd.get_dummies(df, columns=['column_a', 'column_b', 'column_c']) the returning values of both were booleans True and False instead of 0 and 1


Solution

  • By default pd.get_dummies return Boolean, try :

    df = pd.get_dummies(df, dtype=int)