【问题标题】:How to add a name to the columns of a dataframe in pandas如何在 Pandas 中为数据框的列添加名称
【发布时间】:2019-01-19 22:06:50
【问题描述】:

Sample underlined in red

这就是我想要实现的目标。是否有类似于将名称添加到索引的东西或者这不可能?

【问题讨论】:

  • df.columns.names = ['AIRLINE'] 这是您要找的吗?
  • 这看起来像一个交叉表检查 pd.Crosstab

标签: python pandas dataframe


【解决方案1】:

我正在考虑您的数据框的几行和几列。

输入:

df
               AA   AS
DAY_OF_WEEK     
  1           617   2129
  2           9793  9723
  3           4814  4814

就这样吧

df.columns.name = 'AIRLINE'
df

输出:

AIRLINE         AA    AS
DAY_OF_WEEK     
1              617   2129
2              9793  9723
3              4814  4814

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-02
    • 2017-12-03
    • 1970-01-01
    • 2021-04-30
    • 2020-07-19
    • 2021-10-20
    • 2019-10-31
    • 1970-01-01
    相关资源
    最近更新 更多