Reputation: 10695
The following key :GIC-ID
won't return its value "999-99-9999"
. I am trying to figure out why.
Here are the keys -- the first row containing column names of a .csv report. The output is formatted to prevent scrolling:
["AGY/DIV " "STS" "GIC-ID " "LAST-NAME " "FIRST-NAME "
"COVERAGE DESCRIPTION "
"PREMIUM " "RUN-DATE" "BIL MO "]
Here is the data doctored for privacy (output formatted to prevent scrolling):
["666/0010" "ACT" "999-99-9999" "MARGE " "SIMPSON "
"YE OLD PILGRIM FAMILY - INSURED "
"0000.00" "123456789" "99999enter code here"]
I get the first column containing the keys/column headers and the data created with the following including the zipping together of the column names with what will be each row of data.
(def gic-csv-inp (fetch-csv-data "billing_roster.csv"))
(def gic-csv-cols (first gic-csv-inp))
(def gic-csv-data (rest gic-csv-inp))
(def zm2 (zipmap (map #(keyword %1) gic-csv-cols) (first gic-csv-data)))
Now the following keys and data, pulled from a similar but different report, work just fine:
:Employee_SSN "999-99-9999"
That is I can extract the value of the key.
There must be something wrong with the keys, and I can certainly correct those, like removing spaces and so on, but I am not sure what is wrong.
Thanks.
The answer to my question is to trim spaces like this:
(:require [clojure.string :as cstr])
.
.
.
(def zm2 (zipmap (map #(keyword (cstr/trim %1)) gic-csv-cols)
(first gic-csv-data)))
Upvotes: 0
Views: 109
Reputation: 6956
Trimming spaces does work
(def zm2 (zipmap (map #(keyword (re-find #"[^\s]*" %1)) gic-csv-cols) (first gic-csv-data)))
=> (zm2 :GIC-ID)
"999-99-9999"
[^\s]* being a regexp to match all non-whitespace characters
Upvotes: 1