# Problem with CSV.jl reading csv file with extra spaces

**URL:** <https://discourse.julialang.org/t/problem-with-csv-jl-reading-csv-file-with-extra-spaces/67546>\
**Category:** General Usage\
**Tags:** csv\
**Created:** [September 2, 2021, 5:25am UTC](https://discourse.julialang.org/t/problem-with-csv-jl-reading-csv-file-with-extra-spaces/67546 "2021-09-02T05:25:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![xinchin](https://avatars.discourse-cdn.com/v4/letter/x/54ee81/32.png) [@xinchin](https://discourse.julialang.org/u/xinchin)\
**Post date:** [September 2, 2021, 5:25am UTC](https://discourse.julialang.org/t/problem-with-csv-jl-reading-csv-file-with-extra-spaces/67546/1 "2021-09-02T05:25:20Z")

</div>

I’m trying to read a csv file into julia, e.g.

```julia
a,b,c
1,23,4
1, , 5

```

by using

```julia
CSV.File(csvfile, missingstring = " ", types = [Int, Int, Int])

```

but getting this

```julia
2-element CSV.File{false}:
 CSV.Row: (a = 1, b = 23, c = 4)
 CSV.Row: (a = 1, b = missing, c = missing)

```

the problem is the second line column c.  
Also I couldn’t find the feature that it advertises (reading fixed width column)???

---

<div class="post-metadata">

**Author:** ![erickn](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/erickn/32/27431_2.png) [@erickn](https://discourse.julialang.org/u/erickn)\
**Post date:** [September 2, 2021, 5:47am UTC](https://discourse.julialang.org/t/problem-with-csv-jl-reading-csv-file-with-extra-spaces/67546/2 "2021-09-02T05:47:49Z")

</div>

Maybe you can try it without the `missingstring` option to see if that is what you want?

```julia
CSV.File(csvfile, types = [Int, Int, Int])

```

---

<div class="post-metadata">

**Author:** ![lungben](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lungben/32/12314_2.png) [@lungben](https://discourse.julialang.org/u/lungben)\
**Post date:** [September 2, 2021, 6:31am UTC](https://discourse.julialang.org/t/problem-with-csv-jl-reading-csv-file-with-extra-spaces/67546/3 "2021-09-02T06:31:37Z")

</div>

> [@xinchin](#):
>
> `1, , 5`

Could it be due to the leading space before the 5? This value starts with the missing string.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [September 2, 2021, 11:00am UTC](https://discourse.julialang.org/t/problem-with-csv-jl-reading-csv-file-with-extra-spaces/67546/4 "2021-09-02T11:00:33Z")

</div>

In lack of better solution, you could remove all spaces while reading the csv file using [this trick](https://discourse.julialang.org/t/reading-data-text-files-delimited-with-both-spaces-tabs/64851/4) from @GunnarFarneback:

```julia
CSV.File(IOBuffer(replace(read(csvfile, String), " " => "")), missingstring = "", types = [Int, Int, Int])

```

---

<div class="post-metadata">

**Author:** ![xinchin](https://avatars.discourse-cdn.com/v4/letter/x/54ee81/32.png) [@xinchin](https://discourse.julialang.org/u/xinchin)\
**Post date:** [September 3, 2021, 3:01am UTC](https://discourse.julialang.org/t/problem-with-csv-jl-reading-csv-file-with-extra-spaces/67546/5 "2021-09-03T03:01:27Z")

</div>

This is very dangerous trick, it is wasteful too 🤔

---

<div class="post-metadata">

**Author:** ![xinchin](https://avatars.discourse-cdn.com/v4/letter/x/54ee81/32.png) [@xinchin](https://discourse.julialang.org/u/xinchin)\
**Post date:** [September 3, 2021, 3:02am UTC](https://discourse.julialang.org/t/problem-with-csv-jl-reading-csv-file-with-extra-spaces/67546/6 "2021-09-03T03:02:49Z")

</div>

yes space before the 5 is the problem

this is MWE and removing missingstring option is not a solution.
