【问题标题】:Replacing column strings with numbers in a plot在图中用数字替换列字符串
【发布时间】:2021-12-25 09:35:07
【问题描述】:

有没有办法将列号指定为在 x 轴上显示的索引?考虑以下数据框

      Metric Value Metric Value Metric Value Metric Value
0             3            3            7            7
1             1            1            1            1
2             0            0            0            0

下面的代码绘制 row[0] 但是,如您所见,“度量值”写在 x 点上。我希望看到 1、2、3、4。

    row = df.iloc[0]
    row.astype(int).plot()
    plt.show()
    

【问题讨论】:

    标签: python pandas plot


    【解决方案1】:

    试试这个:

    df.columns = range(1, len(df.columns)+1)
    row = df.iloc[0]
    row.astype(int).plot()
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 2021-08-07
      • 2013-05-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-22
      • 2013-05-03
      • 2015-09-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多