sourcelibs/Csv/demos/cities.xtl
1⍝!/usr/bin/env xetal
2⍝# A small dataset as CSV: read it into a table, take columns by name,
3⍝# summarize them with Statistics, and set a report with Format. The
4⍝# data is the file cities.csv beside this program, built in when the
5⍝# program is compiled (X_eTaL's system macro i_nclude<), so it needs no
6⍝# file access when it runs, in a terminal or in the browser.
7⍝# Run with "just demo Csv cities".
8
9ᶜˢ⁼u̲se< "Csv"
10ˢˣ⁼u̲se< "Statistics"
11ᶠ⁼u̲se< "Format"
12data ← @ i̲nclude< "cities.csv"
13t ← ᶜˢr̲ows data
14pop ← "population" ᶜˢn̲umbers t
15area ← "area" ᶜˢn̲umbers t
16
17⍝ Each city's density, people per square kilometre, as a table.
18density ← pop ÷ area
19ᶠt̲able ("city" "people" "per km2") c̲at ((5 1 r̲eshape "city" ᶜˢf̲ield t) c̲at₂ (5 1 r̲eshape ᶠt̲housands pop) c̲at₂ 5 1 r̲eshape ᶠt̲housands density)
20
21ˢˣm̲edian density
22pop ˢˣc̲orrelation area
i̲nclude< expands to
("city,country,population,area\nOslo,Norway,709037,454\n\"Washington, D.C.\",USA,678972,177\nLima,Peru,10092000,2672\nPerth,Australia,2192229,6418\nTurin,Italy,848885,130\n")