Skip to content

Instantly share code, notes, and snippets.

@hancush
Last active January 6, 2017 18:28
Show Gist options
  • Save hancush/70de6a4a9a79a8ad9694c069b7609fbb to your computer and use it in GitHub Desktop.
Save hancush/70de6a4a9a79a8ad9694c069b7609fbb to your computer and use it in GitHub Desktop.
quick bar charts from the command line w agate

requirements

  • agate (pip install agate)

psst! if you're using csvkit, congrats! you've already got agate!

usage

to download make_bars.py, open a terminal to your project directory and run

curl -o make_bars.py https://gist.githubusercontent.com/hancush/70de6a4a9a79a8ad9694c069b7609fbb/raw/46c4caec30f9103b98e8afe37df2f7946487968a/make_bars.py

then pipe your csv via cat or some csvkit utility to it

cat example.csv | python make_bars.py label_column bar_column

where label_column is the column containing your desired bar labels, and bar_column is the column containing your desired bar values.

example output

dist_name      detention_ratio
Harrison                 21.40 ▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Chicago Lawn              9.35 ▓░░░░░░░░░░░░░░░░░░░░░░░░░░░
South Chicago            12.27 ▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Austin                   12.99 ▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Ogden                    15.70 ▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Calumet                  16.52 ▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Gresham                  16.18 ▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Grand Crossing           18.32 ▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Englewood                23.79 ▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Deering                  13.96 ▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Wentworth                14.53 ▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Grand Central            11.89 ▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Morgan Park              13.12 ▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Near West                14.93 ▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Albany Park               7.76 ▓░░░░░░░░░░░░░░░░░░░░░░░
Near North                7.66 ▓░░░░░░░░░░░░░░░░░░░░░░
Central                   9.27 ▓░░░░░░░░░░░░░░░░░░░░░░░░░░░
Jefferson Park            8.60 ▓░░░░░░░░░░░░░░░░░░░░░░░░░
Town Hall                 9.81 ▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Rogers Park              16.93 ▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Shakespeare              10.80 ▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
Lincoln                   7.65 ▓░░░░░░░░░░░░░░░░░░░░░░
                               +---------------------+---------------------+---------------------+---------------------+
                               0.0                  7.5                  15.0                  22.5                 30.0
import sys
import agate
_, labels, bars = sys.argv
table = agate.Table.from_csv(sys.stdin)
table.print_bars(labels, bars)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment