Rounding when reading in decimals from CSV

Is there a way to prevent the data from being rounded after a certain number of decimal points when reading it in from a CSV?

Can you provide an example? It should read up to Float64 precision by default.

2 Likes

Code:
using CSV

nums = CSV.read(β€œdecimal.csv”)

println(nums[2,3])

CSV looks like:
(ignore all the trailing zeros, I just wanted to make sure that all decimal points where shown)

nums
-5.82697322900000000000
16.02264331528420000000
9.29517069756561000000
16.00004654816710000000
221.89095825131400000000
12.71430601365250000000
14.03442272559130000000
4.51014969063621000000
4.28867745292715000000
68.47032628356390000000
93.08060065480470000000
3.76030285138141000000
3.92982841628694000000
6.65743838672069000000
5.84854811215371000000
44.46672462925400000000
66.64378702065490000000
74.60975020120990000000
529.38862193990600000000

Responded below, made error in initial response

So what exactly is the issue you’re seeing? Note that by default, the DataFrame output will show the β€œshort” representation of Float64s, so maybe it just seems like there’s a rounding problem? For example:

julia> df = CSV.read("/Users/jacobquinn/Downloads/decimals.csv")
19Γ—1 DataFrames.DataFrame
β”‚ Row β”‚ csv      β”‚
β”‚     β”‚ Float64  β”‚
β”œβ”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 1   β”‚ -5.82697 β”‚
β”‚ 2   β”‚ 16.0226  β”‚
β”‚ 3   β”‚ 9.29517  β”‚
β”‚ 4   β”‚ 16.0     β”‚
β”‚ 5   β”‚ 221.891  β”‚
β”‚ 6   β”‚ 12.7143  β”‚
β”‚ 7   β”‚ 14.0344  β”‚
β”‚ 8   β”‚ 4.51015  β”‚
β”‚ 9   β”‚ 4.28868  β”‚
β”‚ 10  β”‚ 68.4703  β”‚
β”‚ 11  β”‚ 93.0806  β”‚
β”‚ 12  β”‚ 3.7603   β”‚
β”‚ 13  β”‚ 3.92983  β”‚
β”‚ 14  β”‚ 6.65744  β”‚
β”‚ 15  β”‚ 5.84855  β”‚
β”‚ 16  β”‚ 44.4667  β”‚
β”‚ 17  β”‚ 66.6438  β”‚
β”‚ 18  β”‚ 74.6098  β”‚
β”‚ 19  β”‚ 529.389  β”‚

julia> df[1]
19-element CSV.Column{Float64,Float64}:
  -5.826973229
  16.0226433152842
   9.29517069756561
  16.0000465481671
 221.890958251314
  12.7143060136525
  14.0344227255913
   4.51014969063621
   4.28867745292715
  68.4703262835639
  93.0806006548047
   3.76030285138141
   3.92982841628694
   6.65743838672069
   5.84854811215371
  44.466724629254
  66.6437870206549
  74.6097502012099
 529.388621939906

Notice how looking at the raw Array values show the full precision of the Float64s.

1 Like