【问题标题】:Pandas Dataframe keys to array [duplicate]Pandas Dataframe 键数组[重复]
【发布时间】:2020-11-01 13:39:34
【问题描述】:

我想要一个 dataframe.keys() 方法的值数组。但它返回一个 Index 对象,该对象具有标头值数组作为成员。但我只想要那个数组,没有其他细节。

header_values=features_dataframe.keys()
print(header_values)

输出

索引(['header1', 'header2', 'header3', 'header4', 'header5','目标'], dtype='object')

但我想要

['header1', 'header2', 'header3', 'header4', 'header5','目标']

【问题讨论】:

  • 对不起,我不是在寻找索引,而是在寻找标题!
  • 嗨,请深呼吸。我重新评估了这一点并将副本更改为this oneThis answer我个人赞同。
  • 好的 :) 但您可以标记为重复而无需投票:p
  • 这里的投票是匿名的,请不要假设有人对您投了反对票,因为您可能总是错误地假设。在这种情况下,我没有触摸您问题的否决按钮。

标签: python pandas dataframe


【解决方案1】:

试试看:

header_values = list(features_dataframe.keys())
print(header_values)

【讨论】:

    【解决方案2】:

    尝试:

    list(features_dataframe.index)
    

    【讨论】:

    • 这个答案不正确,它返回的是索引而不是列。
    猜你喜欢
    • 1970-01-01
    • 2021-09-02
    • 1970-01-01
    • 2021-12-24
    • 1970-01-01
    • 2014-07-16
    • 2020-01-03
    • 2021-09-03
    • 1970-01-01
    相关资源
    最近更新 更多