官术网_书友最值得收藏!

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 file 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 file 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.

Getting ready

How to do it…

Now, all you need to do is call incanter.excel/read-xls:

user=> (read-xls "data/small-sample-header.xls")

| given-name | surname |    relation |
|------------+---------+-------------|
|      Gomez |  Addams |      father |
|   Morticia |  Addams |      mother |
|    Pugsley |  Addams |     brother |

How it works…

This can read standard Excel files (.xls) and the XML-based file format introduced in Excel 2003 (.xlsx).

主站蜘蛛池模板: 仁化县| 芜湖市| 鄂托克前旗| 韶关市| 隆回县| 漳浦县| 通城县| 无为县| 玉树县| 岳阳市| 池州市| 大渡口区| 丁青县| 鄂托克前旗| 曲沃县| 永新县| 垫江县| 博兴县| 仙居县| 马尔康县| 宜良县| 聂拉木县| 南投县| 星子县| 赞皇县| 丘北县| 济源市| 涞源县| 胶南市| 桦甸市| 鸡东县| 砀山县| 正安县| 会同县| 沁阳市| 黎平县| 石楼县| 连州市| 五大连池市| 尉氏县| 甘洛县|