mihi-tr / csv-map Goto Github PK
View Code? Open in Web Editor NEWA clojure library for reading well formed csv files as collection of maps.
A clojure library for reading well formed csv files as collection of maps.
Just an idea to keywordize each string key.
(defn parse-csv-k
"parses a csv to a map with keywords as keys
([csv & {:as opts}])
passes options to clojure-csv-k"
[csv & {:as opts}]
(let [opts (vec (reduce concat (vec opts)))
c (apply clojure-csv.core/parse-csv csv opts)]
(map (partial zipmap (keyword (first c))) (rest c))))
returns an empty list for a legit CSV
(first (csv-map.core/parse-csv (slurp "db/etr.csv")))
;; {"" "BURSLEDON ROAD", "Y55" "Y57", "WORCESTERSHIRE" "HAMPSHIRE", "WORCESTER" "SOUTHAMPTON", "ISAAC MADDOX HOUSE" "SOLENT NHS TRUST HEADQUARTERS", "WORCESTERSHIRE HEALTH AND CARE NHS TRUST" "SOLENT NHS TRUST", "Q77" "Q70", "WR4 9RW" "SO19 8BR", "F" "J", "20110701" "20110401", "R1A" "R1C", "0" "0", "SHRUB HILL INDUSTRIAL ESTATE" "HIGHPOINT VENUE"}
(first (clojure-csv.core/parse-csv (slurp "db/etr.csv")))
;; ["R1A" "WORCESTERSHIRE HEALTH AND CARE NHS TRUST" "Y55" "Q77" "ISAAC MADDOX HOUSE" "SHRUB HILL INDUSTRIAL ESTATE" "" "WORCESTER" "WORCESTERSHIRE" "WR4 9RW" "20110701" "" "" "" "" "" "" "" "" "" "" "0" "" "F" "" "" ""]
The second example using clojure-csv.core
is correct. The columns are in the wrong order in the first example.
The source CSV looks like this:
"R1A","WORCESTERSHIRE HEALTH AND CARE NHS TRUST","Y55","Q77","ISAAC MADDOX HOUSE","SHRUB HILL INDUSTRIAL ESTATE","","WORCESTER","WORCESTERSHIRE","WR4 9RW","20110701","","","","","","","","","","","0","","F","","",""
"R1C","SOLENT NHS TRUST","Y57","Q70","SOLENT NHS TRUST HEADQUARTERS","HIGHPOINT VENUE","BURSLEDON ROAD","SOUTHAMPTON","HAMPSHIRE","SO19 8BR","20110401","","","","","","","","","","","0","","J","","",""
"R1D","SHROPSHIRE COMMUNITY HEALTH NHS TRUST","Y55","Q76","WILLIAM FARR HOUSE","MYTTON OAK ROAD","","SHREWSBURY","SHROPSHIRE","SY3 8XL","20110701","","","","","","","","","","","0","","E","","",""
The write-csv function assumes the first line is a header as per clojure-csv, and doesn't correctly map data as returned by parse-csv properly
Otherwise, Heroku doesn't like it:
"Release versions may not depend upon snapshots. Freeze snapshots to dated versions or set the LEIN_SNAPSHOTS_IN_RELEASE environment variable to override."
Thanks!
Looks like this guy has a branch that solves this:
https://github.com/cap10morgan/csv-map/tree/update-deps
cap10morgan@15bb7a4
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.