# Not able to read a csv file

**URL:** <https://discourse.julialang.org/t/not-able-to-read-a-csv-file/76683>\
**Category:** New to Julia\
**Tags:** csv\
**Created:** [February 18, 2022, 9:51am UTC](https://discourse.julialang.org/t/not-able-to-read-a-csv-file/76683 "2022-02-18T09:51:32Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![sai\_matcha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sai_matcha/32/35801_2.png) [@sai\_matcha](https://discourse.julialang.org/u/sai_matcha)\
**Post date:** [February 18, 2022, 9:51am UTC](https://discourse.julialang.org/t/not-able-to-read-a-csv-file/76683/1 "2022-02-18T09:51:32Z")

</div>

earllier i have used CSV.read function very frequnetly. but now it is taking very long time to read CSV file, and finally not giving any result even after 10 minutes .

This is the code im using and , which was uccesfully read in previous instances.

```julia
df1 = CSV.read("path//data.csv",DataFrame,missingstring = "",header = 2)

```

can someone help, why it is happening? Thank you.

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [February 18, 2022, 1:43pm UTC](https://discourse.julialang.org/t/not-able-to-read-a-csv-file/76683/2 "2022-02-18T13:43:23Z")

</div>

Which is the size of the file? Can you share it? What is your version of `CSV.jl`?

---

<div class="post-metadata">

**Author:** ![sai\_matcha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sai_matcha/32/35801_2.png) [@sai\_matcha](https://discourse.julialang.org/u/sai_matcha)\
**Post date:** [February 21, 2022, 3:04am UTC](https://discourse.julialang.org/t/not-able-to-read-a-csv-file/76683/3 "2022-02-21T03:04:33Z")

</div>

these are my all packages list

```julia
(@v1.7) pkg> st
      Status `~/.julia/environments/v1.7/Project.toml`
  [cbdf2221] AlgebraOfGraphics v0.6.5
  [c52e3926] Atom v0.12.36
  [336ed68f] CSV v0.10.2
  [5d742f6a] CSVFiles v1.0.1
  [13f3f980] CairoMakie v0.7.3
  [8be319e6] Chain v0.4.10
  [a93c6f00] DataFrames v1.3.2
  [1313f7d8] DataFramesMeta v0.10.0
  [28b8d3ca] GR v0.64.0
  [c91e804a] Gadfly v1.3.4
  [7073ff75] IJulia v1.23.2
  [e5e0dc1b] Juno v0.8.4
  [bd3c0b08] MissingsAsFalse v0.1.0
  [3beb2ed1] PDFmerger v0.2.0
  [69de0a69] Parsers v2.2.2
  [91a5bcdd] Plots v1.25.10
  [d330b81b] PyPlot v2.10.0
  [1277b4bf] ShiftedArrays v1.0.0
  [f3b207a7] StatsPlots v0.14.33
  [ade2ca70] Dates

```

data contains around 12000 rows and 18 columns.

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [February 21, 2022, 5:58am UTC](https://discourse.julialang.org/t/not-able-to-read-a-csv-file/76683/4 "2022-02-21T05:58:54Z")

</div>

Try using `skipto` to read only a couple of lines.

---

<div class="post-metadata">

**Author:** ![sai\_matcha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sai_matcha/32/35801_2.png) [@sai\_matcha](https://discourse.julialang.org/u/sai_matcha)\
**Post date:** [February 21, 2022, 6:54am UTC](https://discourse.julialang.org/t/not-able-to-read-a-csv-file/76683/5 "2022-02-21T06:54:12Z")

</div>

this is the code i have used

```julia
df1 = CSV.read("path//data.csv",DataFrame,missingstring = "",header = 2,skipto = 4)

```

its still loading for more than 30 minutes.

at the same time load option in CSVFiles is very quick for even big data.  
my only doubt is, i used to read the same dataframe using CSV.read , but suddenly it started to take very long time and not giving any result at the end.

I want to use CSV.read option as well!

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [February 21, 2022, 7:03am UTC](https://discourse.julialang.org/t/not-able-to-read-a-csv-file/76683/6 "2022-02-21T07:03:40Z")

</div>

You’ll need to skip more than 4 lines to make a difference.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [February 21, 2022, 7:28am UTC](https://discourse.julialang.org/t/not-able-to-read-a-csv-file/76683/7 "2022-02-21T07:28:27Z")

</div>

Why not just `limit = 2` if you only want to read a couple of lines?

---

<div class="post-metadata">

**Author:** ![sai\_matcha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sai_matcha/32/35801_2.png) [@sai\_matcha](https://discourse.julialang.org/u/sai_matcha)\
**Post date:** [February 21, 2022, 9:48am UTC](https://discourse.julialang.org/t/not-able-to-read-a-csv-file/76683/8 "2022-02-21T09:48:04Z")

</div>

limit to 11000 also same result

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [February 21, 2022, 10:32am UTC](https://discourse.julialang.org/t/not-able-to-read-a-csv-file/76683/9 "2022-02-21T10:32:12Z")

</div>

Just to be clear `skipto=n` skips the first `n` rows, while `limit=n` will only read the first `n` rows. So if you only want to read 2 rows, you do `limit=2` or `skipto=x-2` where `x` is the total number of rows in your file.

That said 11,000 rows isn’t very long and shouldn’t take more than a second or two, depending on how many columns you have. You still haven’t told us the size of the file.

---

<div class="post-metadata">

**Author:** ![sai\_matcha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sai_matcha/32/35801_2.png) [@sai\_matcha](https://discourse.julialang.org/u/sai_matcha)\
**Post date:** [February 21, 2022, 11:06am UTC](https://discourse.julialang.org/t/not-able-to-read-a-csv-file/76683/10 "2022-02-21T11:06:11Z")

</div>

filesize - 903 kb

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [February 21, 2022, 11:15am UTC](https://discourse.julialang.org/t/not-able-to-read-a-csv-file/76683/11 "2022-02-21T11:15:08Z")

</div>

That size should take a fraction of a second to read. Can you share the file? Is this a problem for all files you are reading in or just a specific file?

---

<div class="post-metadata">

**Author:** ![sai\_matcha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sai_matcha/32/35801_2.png) [@sai\_matcha](https://discourse.julialang.org/u/sai_matcha)\
**Post date:** [February 24, 2022, 5:04am UTC](https://discourse.julialang.org/t/not-able-to-read-a-csv-file/76683/12 "2022-02-24T05:04:08Z")

</div>

HI, i tried with different CSV files. its happening with all files

---

<div class="post-metadata">

**Author:** ![tk3369](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tk3369/32/2824_2.png) [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Post date:** [February 24, 2022, 7:27am UTC](https://discourse.julialang.org/t/not-able-to-read-a-csv-file/76683/13 "2022-02-24T07:27:32Z")

</div>

Is the file located in a network drive? Even so, the timing that you reported was still unreasonably long….

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [February 24, 2022, 8:30am UTC](https://discourse.julialang.org/t/not-able-to-read-a-csv-file/76683/14 "2022-02-24T08:30:18Z")

</div>

It’s very hard to check what’s going on if you can’t share the csv file. What if you do:

```julia
julia> using CSV, DataFrames

julia> CSV.write("test.csv", DataFrame(rand(1_000_000, 10), :auto));

julia> filesize("test.csv")/1e6 # This is about a 200MB csv
192.697339

julia> @time CSV.read("test.csv", DataFrame);
 10.003148 seconds (42.79 M allocations: 1.836 GiB, 3.27% gc time, 85.23% compilation time)

julia> @time CSV.read("test.csv", DataFrame);
  1.297614 seconds (40.00 M allocations: 1.723 GiB, 15.92% gc time)

```

First call is to get a sense of the compilation overhead, second call is the “typical” time after compilation. So reading in a 200MB csv takes about a second on my machine. This is with a single thread, when adding threads I get (in a new session, second call to `CSV.read`):

```julia
julia> Threads.nthreads()
2

julia> @time CSV.read("test.csv", DataFrame);
  0.351343 seconds (3.62 k allocations: 81.311 MiB)

```

---

<div class="post-metadata">

**Author:** ![mgp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mgp/32/28599_2.png) [@mgp](https://discourse.julialang.org/u/mgp)\
**Post date:** [March 1, 2022, 11:40am UTC](https://discourse.julialang.org/t/not-able-to-read-a-csv-file/76683/15 "2022-03-01T11:40:37Z")

</div>

I had an equivalent issue. After trawling discussions, I found a suggestion of setting Parsers to version 2.2.0, which fixed it for me:

```julia
add Parsers @2.2.0
pin Parsers

```

---

<div class="post-metadata">

**Author:** ![sai\_matcha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sai_matcha/32/35801_2.png) [@sai\_matcha](https://discourse.julialang.org/u/sai_matcha)\
**Post date:** [March 2, 2022, 5:42am UTC](https://discourse.julialang.org/t/not-able-to-read-a-csv-file/76683/16 "2022-03-02T05:42:31Z")

</div>

Thank you tried it… but no result

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [March 2, 2022, 5:48am UTC](https://discourse.julialang.org/t/not-able-to-read-a-csv-file/76683/17 "2022-03-02T05:48:24Z")

</div>

`CSV.read` sometimes hangs during compilation, so I switched to [DelimitedFiles](https://docs.julialang.org/en/v1/stdlib/DelimitedFiles/).

---

<div class="post-metadata">

**Author:** ![ceysa75](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ceysa75/32/19121_2.png) [@ceysa75](https://discourse.julialang.org/u/ceysa75)\
**Post date:** [March 2, 2022, 7:26am UTC](https://discourse.julialang.org/t/not-able-to-read-a-csv-file/76683/18 "2022-03-02T07:26:32Z")

</div>

> [@nilshg](#):
>
> Just to be clear `skipto=n` skips the first `n` rows

Isn’t that skipto=n means which row to start with? So the term skip is a bit irritating here, or am I wrong?

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [March 2, 2022, 7:32am UTC](https://discourse.julialang.org/t/not-able-to-read-a-csv-file/76683/19 "2022-03-02T07:32:20Z")

</div>

I don’t know, seems pretty self-explanatory to me. “Skip to the nth line” isn’t any less clear than “start at the nth line”, and can’t be confused with Startat, my local tattoo parlor.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [March 2, 2022, 7:57am UTC](https://discourse.julialang.org/t/not-able-to-read-a-csv-file/76683/20 "2022-03-02T07:57:15Z")

</div>

I think the only confusion was my choice of words - indeed `skipto` skips **to** the n-th row, rather than skipping **the** first n rows (which would imply skipping **to** row n+1).
