-
-
Save mmower/b755a0b6f88292d9cec2 to your computer and use it in GitHub Desktop.
Parse a CSV file containing rows like "2008,08,1.8,45454,8900,coupe" into a map that looks like: { "2008/1.8/coupe" [ {:mileage 45454 :price 8900}, ... ] ... } that can be further used to extract summary stats.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn group-car-data-by-model [in-file] | |
(with-open [in-file (io/reader in-file)] | |
(loop [results {} | |
rows (doall (csv/read-csv in-file))] | |
(if (empty? rows) | |
results | |
(let [[year reg engine mileage price kind] (first rows) | |
model (str year "/" engine "/" kind) | |
cars (get-in results [model] [])] | |
(recur (assoc-in results [model] (conj cars {:mileage mileage | |
:price price})) | |
(rest rows))))))) | |
(println (group-car-data-by-model (project-path "mx5.csv"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment