使用 drop_first 时更改分配的虚拟变量分类
我为用于线性回归模型的数据生成了以下虚拟变量。
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()
我希望分类列虚拟变量为classification_ckd
我该如何实现这一点?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用这样的前缀
pd.get_dummies(df, prefix=['col1', 'col2'])
。阅读本文档的更多详细信息 Pandas-doc
You need to use prefix like this
pd.get_dummies(df, prefix=['col1', 'col2'])
.Read further details from this documentation Pandas-doc