Database Reference
In-Depth Information
How it works…
Similar to all Lisp's (List Processing), Clojure is usually read from the inside out and from
right to left. Let's break it down. clojure.java.io/reader opens the ile for reading.
read-all-json parses all of the JSON documents in the ile into a sequence. In this case, it
returns a vector of the maps. incanter.core/to-dataset takes a sequence of maps and
returns an Incanter dataset. This dataset will use the keys in the maps as column names, and
it will convert the data values into a matrix. Actually, to-dataset can accept many different
data structures. Try doc to-dataset in the REPL ( doc shows the documentation string
attached to the function), or see the Incanter documentation at http://data-sorcery.
org/contents/ for more information.
Reading data from Excel with Incanter
We've seen how Incanter makes a lot of common data-processing tasks very simple, and
reading an Excel spreadsheet is another example of this.
Getting ready
First, make sure that your Leiningen project.clj ile contains the right dependencies:
(defproject getting-data "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.6.0"]
[incanter "1.5.5"]"]])
Also, make sure that you've loaded those packages into the REPL or script:
(use 'incanter.core
'incanter.excel)
Find the Excel spreadsheet you want to work on. The ile name of my spreadsheet is data/
small-sample-header.xls , as shown in the following screenshot. You can download this
from http://www.ericrochester.com/clj-data-analysis/data/small-sample-
header.xls .
 
Search WWH ::




Custom Search