clojure-csv icon indicating copy to clipboard operation
clojure-csv copied to clipboard

Numbers aren't recognised as numbers

Open simon-brooke opened this issue 6 years ago • 1 comments
trafficstars

Given this input data row:

Aldershot;Leo Docherty;12;Hampshire;76205;26955;15477;3637;1796;1090;0;0;0

(from here)

I get this output:

["Aldershot" "Leo Docherty" "12" "Hampshire" "76205" "26955" "15477" "3637" "1796" "1090" "0" "0" "0"]

In other words, numbers are being recognised only as strings.

I wrote a wee function which sorts this:

(defn numbers-as-numbers
  "Return a list like the sequence `l`, but with all those elements
  which are string representations of numbers replaced with numbers."
  [l]
  (map #(if 
          (string? %) 
          (try 
            (let [n (read-string %)]
              (if (number? n) n %))
            (catch Exception e %))
          %) 
       l))

I'll try to do a pull request later today with this added in.

simon-brooke avatar Mar 23 '19 09:03 simon-brooke

The parse-csv function is meant to return a vector of strings. It is a different game to convert some values to numbers.

randomizedthinking avatar Oct 17 '20 05:10 randomizedthinking