9345

How do I convert this csv data into a bar chart?

<h3>Question</h3>

Tour = Tour Name

Start = Available reservations at the start

End = Amount of reservations left

csv file columns:

ID | Tour | Start | End 12345 | Italy | 100 | 80 13579 | China | 50 | 30 24680 | France | 50 | 30

I have this so far

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

I want to make a bar chart that looks something like this with this given data.


<h3>Answer1:</h3>

IIUC, call set_index and plot.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() <hr />

If you're interested in <em>annotating</em> the bars too, take a look at Annotate bars with values on Pandas bar plots.


<h3>Answer2:</h3>

You can also do this without set_index()

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

来源:https://stackoverflow.com/questions/47339352/how-do-i-convert-this-csv-data-into-a-bar-chart

Recommend

  • How can I add a plural-s after a Sphinx :class: directive
  • How do I convert this csv data into a bar chart?
  • 大白话5分钟带你走进人工智能-第37节神经网络之反向传播详细案例及解释(5)
  • Wordpress ecommerce plugin allowing client to upload image [closed]
  • Unable to connect to host MySQL database on application deployed to CloudBees
  • How to use application:get_env() in Erlang/OTP?
  • How to use Ignore globally in AutoMapper?
  • How to capture self consuming variable in a struct?
  • The term 'add-migration' is not recognized as the name of a cmdlet
  • Using global-method-security, Access Denied errors are returned as HTTP 500 errors
  • Density plot using seaborn
  • Full stack trace for intercepted methods at call site in Unity
  • Class properties must be methods. Expected '(' but instead saw '='
  • python: unpack IBM 32-bit float point
  • pan gesture issue, slight movement within UIButton detection
  • Run WinForms control inside WebForms and take screenshot of it
  • Matplotlib log-scale tick labels, minus sign too long in latex font
  • stream mp3 file express server with ability to fast forward/rewind
  • PHP Text to graphical smiley [duplicate]
  • Imprecise numbers with microtime and floating point addition in PHP
  • How to do “highlighting” on gameObject
  • How to configure server to allow large file downloads?
  • Laravel - Collection with relations take a lot of time
  • python: unpacking a string to a list
  • Is this algorithm correct for finding period of a string?
  • How do you save a custom class as an attribute of a CoreData entity in Swift 3?
  • How to add a method to the versions model of Paper_trail?
  • disable EJS caching in production
  • Chromedriver works manually but fails when ran from Jenkins Slave
  • Android: Compressing images creates black borders on left and top margin
  • Setting up Wordpress and Flask on Apache2
  • How to force Delphi to use D8.bat instead of dx.bat to compile Java 1.8 bytecode into DEX bytecode
  • jquery hide columns in table based on dropdown select
  • AVPlayer blank video: playing sound but no video
  • How to set a dynamic form fields to dirty or touched with angular?
  • Identifying dates in strings using NLTK
  • Overwrite text file programmatically