# CSV.read Error - provide a valid sink argument

**URL:** <https://discourse.julialang.org/t/csv-read-error-provide-a-valid-sink-argument/50157>\
**Category:** General Usage\
**Tags:** csv\
**Created:** [November 14, 2020, 7:27pm UTC](https://discourse.julialang.org/t/csv-read-error-provide-a-valid-sink-argument/50157 "2020-11-14T19:27:27Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vaclav\_Dekanovsky](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vaclav_dekanovsky/32/19431_2.png) [@Vaclav\_Dekanovsky](https://discourse.julialang.org/u/Vaclav_Dekanovsky)\
**Post date:** [November 14, 2020, 7:27pm UTC](https://discourse.julialang.org/t/csv-read-error-provide-a-valid-sink-argument/50157/1 "2020-11-14T19:27:27Z")

</div>

I’ve just installed Julia on Win-64 and I try to read a CSV file.

The following code works:

```julia
using CSVFiles, FileIO, DataFrames

df = load("C:\\...\\file.csv") |> DataFrame

```

But I wonder what is missing in this code:

```julia
[In]
using CSV
CSV.read("C:\\...\\file.csv")

[Out]
ArgumentError: provide a valid sink argument, like `CSV.read(source, DataFrame)`

```

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [November 14, 2020, 7:28pm UTC](https://discourse.julialang.org/t/csv-read-error-provide-a-valid-sink-argument/50157/2 "2020-11-14T19:28:30Z")

</div>

The error gives you the answer! just change the code to

```julia
CSV.read("C:\\...\\file.csv", DataFrame)

```

---

<div class="post-metadata">

**Author:** ![Vaclav\_Dekanovsky](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vaclav_dekanovsky/32/19431_2.png) [@Vaclav\_Dekanovsky](https://discourse.julialang.org/u/Vaclav_Dekanovsky)\
**Post date:** [November 14, 2020, 7:44pm UTC](https://discourse.julialang.org/t/csv-read-error-provide-a-valid-sink-argument/50157/3 "2020-11-14T19:44:17Z")

</div>

Oh, cool. You have to `add DataFrames` as well, because without it I receive another error.

```julia
[In]:
using CSV
CSV.read("C:\\...\\file.csv", DataFrame)

[Out]:
UndefVarError: DataFrame not defined

```

So how do I define a data frame?  
I’ve done my research and read:

- [Home · CSV.jl](https://juliadata.github.io/CSV.jl/stable/index.html)
- [How to Import a CSV File into Julia (example included) - Data to Fish](https://datatofish.com/import-csv-julia/)
- …

No where I find any guidance how to define any DataFrame, whether it’s a variable or what.

But then I’ve tried the following code, which finally works.

```julia
using CSV
using DataFrames

CSV.read("C:\\...\\benchmark.csv", DataFrame)

```

Though I have no idea why. `What is the relation between DataFrames package and DataFrame?` Julia seems to have a less steep learning curve than I have expected, but that’s good since I plan to write tutorials about it, once I understand.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [November 14, 2020, 8:23pm UTC](https://discourse.julialang.org/t/csv-read-error-provide-a-valid-sink-argument/50157/4 "2020-11-14T20:23:56Z")

</div>

The package `DataFraames.jl` defines the `DataFrame` type.

In your code you can assign an instantiated `DataFrame` object like

```julia
df = CSV.read("C:\\...\\benchmark.csv", DataFrame)

```

Note that in the above line, the `DataFrame` is _not_ an instantiated data frame. Rather, it’s the `Type` `DataFrame`.

In julia, `Type`s come with constructors, so the code above is just shorthand for

```julia
df = DataFame(CSV.File("..."))

```

where the output of `CSV.FIle` is something the `DataFrame` type has defined a constructor for.

Unfortunately, the second link below is an outdated tutorial. This is a bit of a pain, but as the ecosystem stabilizes over time hopefully it will be harder to stumble across outdated tutorials.

---

<div class="post-metadata">

**Author:** ![Vaclav\_Dekanovsky](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vaclav_dekanovsky/32/19431_2.png) [@Vaclav\_Dekanovsky](https://discourse.julialang.org/u/Vaclav_Dekanovsky)\
**Post date:** [November 14, 2020, 8:32pm UTC](https://discourse.julialang.org/t/csv-read-error-provide-a-valid-sink-argument/50157/5 "2020-11-14T20:32:02Z")

</div>

Thank you very much @pdeffebach for the detailed explanation. Now it makes sense to me.  
I’m aware that there’s still some evolution of Julia, and I’ll try to comment on the outdated data sources to help others avoid the issues I have because all the tutorials were showing the same approach which no longer works.

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [November 14, 2020, 9:38pm UTC](https://discourse.julialang.org/t/csv-read-error-provide-a-valid-sink-argument/50157/6 "2020-11-14T21:38:14Z")

</div>

Maybe the error should be a bit more precise:

```julia
ArgumentError: provide a valid sink argument, like `using DataFrames; CSV.read(source, DataFrame)`

```

@quinnj What do you think?

---

<div class="post-metadata">

**Author:** ![quinnj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quinnj/32/11_2.png) [@quinnj](https://discourse.julialang.org/u/quinnj)\
**Post date:** [November 14, 2020, 11:51pm UTC](https://discourse.julialang.org/t/csv-read-error-provide-a-valid-sink-argument/50157/7 "2020-11-14T23:51:36Z")

</div>

Sure thing; can someone make a PR?

---

<div class="post-metadata">

**Author:** ![nalimilan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nalimilan/32/147_2.png) [@nalimilan](https://discourse.julialang.org/u/nalimilan)\
**Post date:** [November 15, 2020, 10:08am UTC](https://discourse.julialang.org/t/csv-read-error-provide-a-valid-sink-argument/50157/8 "2020-11-15T10:08:39Z")

</div>

Sure: [https://github.com/JuliaData/CSV.jl/pull/775](https://github.com/JuliaData/CSV.jl/pull/775)

---

<div class="post-metadata">

**Author:** ![Charles\_Brodhead\_III](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/charles_brodhead_iii/32/9441_2.png) [@Charles\_Brodhead\_III](https://discourse.julialang.org/u/Charles_Brodhead_III)\
**Post date:** [November 19, 2020, 6:20am UTC](https://discourse.julialang.org/t/csv-read-error-provide-a-valid-sink-argument/50157/10 "2020-11-19T06:20:09Z")

</div>

Hi. Is there any reason why the behavior changed?

df = DataFrame(CSV.read(data\_file)) \>\> ERROR: ArgumentError: provide a valid sink argument, like `CSV.read(source, DataFrame)`  
df = CSV.read(data\_file,DataFrame) \>\> 295×2 DataFrame

---

<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:** [November 19, 2020, 6:50am UTC](https://discourse.julialang.org/t/csv-read-error-provide-a-valid-sink-argument/50157/11 "2020-11-19T06:50:11Z")

</div>

The `DataFrame` one should be `DataFrame(CSV.File(data_file))` and still works. `CSV.read` used to work with a dataframe output as default, but was deprecated so CSV.jl doesn’t have to depend on DataFrames.jl

It was then brought back as `CSV.read(filepath, sink)` as users were expecting a CSV.read function, and this structure means DataFrames only has to be loaded by the user if a DataFrame output is actually required.

---

<div class="post-metadata">

**Author:** ![Charles\_Brodhead\_III](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/charles_brodhead_iii/32/9441_2.png) [@Charles\_Brodhead\_III](https://discourse.julialang.org/u/Charles_Brodhead_III)\
**Post date:** [November 24, 2020, 2:54am UTC](https://discourse.julialang.org/t/csv-read-error-provide-a-valid-sink-argument/50157/12 "2020-11-24T02:54:23Z")

</div>

@nilshg Your explanation is much appreciated, thx.

---

<div class="post-metadata">

**Author:** ![Vaclav\_Dekanovsky](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vaclav_dekanovsky/32/19431_2.png) [@Vaclav\_Dekanovsky](https://discourse.julialang.org/u/Vaclav_Dekanovsky)\
**Post date:** [February 22, 2021, 10:04pm UTC](https://discourse.julialang.org/t/csv-read-error-provide-a-valid-sink-argument/50157/13 "2021-02-22T22:04:29Z")

</div>

I’ve summarized what I have learned here into an article here - [Read CSV to Data Frame in Julia](https://towardsdatascience.com/read-csv-to-data-frame-in-julia-programming-lang-77f3d0081c14). It describes three syntactic ways, talks about encoding and shows examples of the several of the parameters. Thanks evreyone for help.
