CSV の読み書きをするライブラリ。パースした結果はベクタのリストになる。
GitHub
https://github.com/clojure/data.csv
ドキュメント
http://clojure.github.io/data.csv/
(ns clj-data.csv)
(require '[clojure.data.csv :as csv])
(let [filename "usa-states.csv"
csv (slurp filename)
rows (csv/read-csv csv)]
rows)
(let [filename "usa-states.csv"
csv (slurp filename)
rows (csv/read-csv csv)]
(doseq [row rows]
(let [code (first row)
name (second row)]
(println (str code " => " name)))))
(let [filename "test.ltsv"
csv (slurp filename)
rows (csv/read-csv csv :separator \tab)]
(map (fn [row]
(str (first row) " => " (second row)))
rows))
(with-out-str
(csv/write-csv *out* [["foo" "bar"]
["baz" "qux"]]))
(csv/write-csv *out* [["foo" "bar"]
["baz" "qux"]
["I'm" "pen"]]
:separator \tab)
サンプルコードとサンプルデータ
https://github.com/kyanny/playground/tree/gh-pages/clj-data.csv