Database Reference
In-Depth Information
Saving data as JSON
To save a dataset as JSON, open a ile and use clojure.data.json/write to serialize
the ile:
(with-open [f-out (io/writer "data/chn-2000.json")]
(json/write (:rows data2000) f-out))
How it works…
For CSV and JSON, as well as many other data formats, the process is very similar. Get the
data, open the ile, and serialize data into it. There will be differences in how the output
function wants the data ( to-list or :rows ), and there will be differences in how the output
function is called (for instance, whether the ile handle is the irst or second argument).
But generally, outputting datasets will be very similar and relatively simple.
See also…
In Chapter 1 , Importing Data for Analysis , we talked about how to read CSV iles ( Reading CSV
data into Incanter datasets recipe) and JSON iles ( Reading JSON data into Incanter datasets
recipe) into Incanter.
Projecting from multiple datasets with $join
So far, we've been focusing on splitting up datasets, on dividing them into groups of rows or
groups of columns with functions and macros such as $ or $where . However, sometimes we'd
like to move in the other direction. We might have two related datasets and want to join them
together to make a larger one. For example, we might want to join crime data to census data,
or take any two related datasets that come from separate sources and analyze them together.
Getting ready
First, we'll need to include these dependencies in our project.clj ile:
(defproject inc-dsets "0.1.0"
:dependencies [[org.clojure/clojure "1.6.0"]
[incanter "1.5.5"]
[org.clojure/data.csv "0.1.2"]])
 
Search WWH ::




Custom Search