python - 如何将列名提取到列表中
问题描述
我是 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
是数据框吗?我将不胜感激有关如何将列名提取到功能列表中的帮助。
谢谢您的帮助!
解决方案
推荐阅读
- r - 如何根据 R 中的其他列对特定列中的值进行分类
- google-bigquery - BigQuery 加载作业将 Null 视为 String 而不是 Float (json)
- python - 我应该如何提高 Python/Cython 的性能?并行化/memoryviews/numpy?
- php - 支持负值
- javascript - Awat 不等待异步
- python - 将列表中的元素转换为单独的行
- math - 寻找二维平面的隐式表示
- python - @pytest 个人测试装饰器即使在失败后也能继续断言?
- html - 用于基于电子的应用程序的类似 Wiki 的表格排序
- r - 在R中,找到给定特定列的相邻行