patient_dummies = pd.get_dummies(df['PatientSerial'], prefix='Serial_', drop_first = True)
df = pd.concat([df, patient_dummies], axis = 1)
df.drop(['PatientSerial'], inplace = True, axis = 1)
machine_dummies = pd.get_dummies(df['MachineID'], drop_first = True)
df = pd.concat([df, machine_dummies], axis = 1)
df.drop(['MachineID'], inplace = True, axis = 1)
I have two columns in dataframe df that I want to change into unordered categorical variables. Instead of doing each one separately, is there more efficient way to accomplish this? I was thinking of the following way:
patient_dummies = pd.get_dummies(df['PatientSerial'], prefix='Serial_', drop_first = True)
machine_dummies = pd.get_dummies(df['MachineID'], drop_first = True)
df = pd.concat([df, patient_dummies + machine_dummies], axis = 1)
df.drop(['PatientSerial','MachineID'], inplace = True, axis = 1)
But this didn't work; it generated 'nan' for all the entries instead of 0's and 1's.