【问题标题】:How do I convert this csv data into a bar chart?如何将此 csv 数据转换为条形图?
【发布时间】:2017-11-16 21:27:15
【问题描述】:

旅游 = 旅游名称

开始 = 开始时的可用预订

End = 剩余预订量

csv 文件列:

ID     |   Tour   | Start | End

12345  |  Italy   |  100  | 80

13579  |  China   |  50   | 30

24680  |  France  |  50   | 30

到目前为止我有这个

import pandas as pd

df = pd.read_csv("items4.csv",sep=",").set_index('ID')

d = dict(zip(df.index,df.values.tolist()))

print(d)
{12345: ['Italy', 100, 80], 13579: ['China', 50, 30], 24680: ['France', 50, 30]} #This is the output

我想用给定的数据制作一个类似于this 的条形图。

【问题讨论】:

  • 请看this是否有帮助。

标签: python pandas plot


【解决方案1】:

IIUC,请致电set_indexplot.bar

df

      ID    Tour  Start  End
0  12345   Italy    100   80
1  13579   China     50   30
2  24680  France     50   30

df.set_index('Tour')[['Start', 'End']].plot.bar()
plt.show()

如果您也对注释条感兴趣,请查看Annotate bars with values on Pandas bar plots

【讨论】:

    【解决方案2】:

    不使用 set_index() 也可以这样做

    df.plot.bar(x = 'Tour', y = ['Start', 'End'])
    

    【讨论】:

      猜你喜欢
      • 2021-09-22
      • 2017-05-27
      • 1970-01-01
      • 1970-01-01
      • 2021-07-19
      • 2020-05-12
      • 1970-01-01
      • 1970-01-01
      • 2019-07-13
      相关资源
      最近更新 更多