Database Reference
In-Depth Information
(defn read-country-data [filename]
(with-open [r (io/reader filename)]
(i/to-dataset
(doall (with-header
(drop 2 (csv/read-csv r)))))))
2.
Now, using these functions, we can load the data:
user=> (def chn-data (read-country-data data-file))
3.
We can select columns to be pulled out from the dataset by passing the column
names or numbers to the $ macro. It returns a sequence of the values in the column:
user=> (i/$ :Indicator-Code chn-data)
("AG.AGR.TRAC.NO" "AG.CON.FERT.PT.ZS" "AG.CON.FERT.ZS" …
4.
We can select more than one column by listing all of them in a vector. This time, the
results are in a dataset:
user=> (i/$ [:Indicator-Code :1992] chn-data)
| :Indicator-Code | :1992 |
|---------------------------+---------------------|
| AG.AGR.TRAC.NO | 770629 |
| AG.CON.FERT.PT.ZS | |
| AG.CON.FERT.ZS | |
| AG.LND.AGRI.K2 | 5159980 |
5.
We can list as many columns as we want, although the formatting might suffer:
user=> (i/$ [:Indicator-Code :1992 :2002] chn-data)
| :Indicator-Code | :1992 |
:2002 |
|---------------------------+---------------------+---------------
------|
| AG.AGR.TRAC.NO | 770629 |
|
| AG.CON.FERT.PT.ZS | |
122.73027213719 |
| AG.CON.FERT.ZS | |
373.087159048868 |
| AG.LND.AGRI.K2 | 5159980 |
5231970 |
 
Search WWH ::




Custom Search