首页 > 解决方案 > 如何将列名提取到列表中

问题描述

我是 python 新手,如果有人能提供帮助,我将不胜感激:

我想对数据帧应用一种热编码:

features_specs_train_ohe = pd.get_dummies(features_specs_train)

这应该会产生一个新的数据框(features_specs_train_ohe)。

但是,当我申请

features = list(features_specs_train_ohe.columns) 

我得到了错误

“numpy.ndarray”对象没有属性“列”。

为什么是这样?不应该features_specs_train_ohe是数据框吗?我将不胜感激有关如何将列名提取到功能列表中的帮助。

谢谢您的帮助!

标签: pythonpandaslistdummy-variable

解决方案


推荐阅读