'Changing the assigned dummy variable classification when using drop_first
I generated the following dummy variables for the data to be used for a linear regression model.
data = df.copy() #make a copy of our cleaned dataset called data
X = data[['age', 'blood_pressure', 'specific_gravity', 'albumin', 'sugar',
'pus_cell', 'pus_cell_clumps', 'bacteria', 'blood_glucose_random',
'blood_urea', 'serum_creatinine', 'sodium', 'potassium', 'hemoglobin',
'packed_cell_volume', 'white_blood_cell_count', 'red_blood_cell_count',
'hypertension', 'diabetes_mellitus', 'coronary_artery_disease',
'appetite', 'pedal_edema', 'anemia','classification'
]]
#convert all object/category columns into dummy/indicator variables.
X = pd.get_dummies(data= X, drop_first=True)
X.head()
I want the classification column dummy variable to be classification_ckd
How can I accomplish this?
Solution 1:[1]
You need to use prefix like this pd.get_dummies(df, prefix=['col1', 'col2']).
Read further details from this documentation Pandas-doc
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | PKS |

