# How to use the CSV.read? error "provide a valid sink argument"

**URL:** https://discourse.julialang.org/t/how-to-use-the-csv-read-error-provide-a-valid-sink-argument/51076
**Category:** Teaching & Outreach
**Created:** [December 2, 2020, 2:10am UTC](https://discourse.julialang.org/t/how-to-use-the-csv-read-error-provide-a-valid-sink-argument/51076 "2020-12-02T02:10:29Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Marc\_Hillocks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marc_hillocks/32/19894_2.png) [@Marc\_Hillocks](https://discourse.julialang.org/u/Marc_Hillocks)
#### Post date: [December 2, 2020, 2:10am UTC](https://discourse.julialang.org/t/how-to-use-the-csv-read-error-provide-a-valid-sink-argument/51076/1 "2020-12-02T02:10:29Z")

</div>

Hey everyone, I’m trying to use the CSV.read method, however I keep getting the argument “provide a valid sink argument”. I’ve tried putting in the path to my csv file I’m trying to load, but it still doesn’t work. The code I’ve used is as follows:

‘’’  
Pkg.add(“CSV”)  
Pkg.add(“DataFrames”)  
using CSV, DataFrames

project\_data = using DataFrames; CSV.read(“/Users/odionhillocks/Desktop/Project6925/Data.csv”, DataFrame)

‘’’

---

<div class="post-metadata">

### Author: ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)
#### Post date: [December 2, 2020, 2:30am UTC](https://discourse.julialang.org/t/how-to-use-the-csv-read-error-provide-a-valid-sink-argument/51076/2 "2020-12-02T02:30:13Z")

</div>

Hi Marc, welcome to the community! It’s hard to diagnose this sort of issue if the reader can’t reproduce it. Can you provide more details (ideally a reproducible example following these [guidelines](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757))?

---

<div class="post-metadata">

### Author: ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)
#### Post date: [December 2, 2020, 2:33am UTC](https://discourse.julialang.org/t/how-to-use-the-csv-read-error-provide-a-valid-sink-argument/51076/3 "2020-12-02T02:33:59Z")

</div>

Try using `CSV.File` instead of `CSV.read`; I believe the latter might be only for reading into a specific Tables.jl-compatible sink (which is not what most users actually want).

---

<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: [December 2, 2020, 2:42am UTC](https://discourse.julialang.org/t/how-to-use-the-csv-read-error-provide-a-valid-sink-argument/51076/4 "2020-12-02T02:42:40Z")

</div>

you want the following

```julia
using DataFrames, CSV
df = CSV.read(file, DataFrame)

```

---

<div class="post-metadata">

### Author: ![Marc\_Hillocks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marc_hillocks/32/19894_2.png) [@Marc\_Hillocks](https://discourse.julialang.org/u/Marc_Hillocks)
#### Post date: [December 2, 2020, 3:08am UTC](https://discourse.julialang.org/t/how-to-use-the-csv-read-error-provide-a-valid-sink-argument/51076/5 "2020-12-02T03:08:06Z")

</div>

But what goes in the place of “file” I tried putting the path to my file and it doesn’t work, if i put the file name only, it tells me the file is not valid.

The code I tried is placed below:

Pkg.add(“CSV”)  
Pkg.add(“DataFrames”)  
using CSV, DataFrames

project\_data = using DataFrames; CSV.File(“/Users/odionhillocks/Desktop/Project6925/Data.csv”, DataFrame)

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [December 2, 2020, 3:10am UTC](https://discourse.julialang.org/t/how-to-use-the-csv-read-error-provide-a-valid-sink-argument/51076/6 "2020-12-02T03:10:02Z")

</div>

examples from documentation:

```julia
df = CSV.File(file) |> DataFrame

```

`file` is the path to your file (basically what you already have up there)

---

<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: [December 2, 2020, 3:11am UTC](https://discourse.julialang.org/t/how-to-use-the-csv-read-error-provide-a-valid-sink-argument/51076/7 "2020-12-02T03:11:38Z")

</div>

your code has `CSV.File(file, DataFrame)`. You need `CSV.read(file, DataFrame)`

---

<div class="post-metadata">

### Author: ![Marc\_Hillocks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marc_hillocks/32/19894_2.png) [@Marc\_Hillocks](https://discourse.julialang.org/u/Marc_Hillocks)
#### Post date: [December 2, 2020, 3:14am UTC](https://discourse.julialang.org/t/how-to-use-the-csv-read-error-provide-a-valid-sink-argument/51076/8 "2020-12-02T03:14:56Z")

</div>

This is what I have now and I’m still getting the “provide a valid sink” error.

Pkg.add(“CSV”)  
Pkg.add(“DataFrames”)  
using DataFrames, CSV

project\_data = using DataFrames; CSV.read(“/Users/odionhillocks/Desktop/Project6925/Data.csv”, 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: [December 2, 2020, 3:27am UTC](https://discourse.julialang.org/t/how-to-use-the-csv-read-error-provide-a-valid-sink-argument/51076/9 "2020-12-02T03:27:58Z")

</div>

Can you run the following code?

```julia
julia> using CSV, DataFrames

julia> df = DataFrame(a = [1, 2], b = ["x", "z"]);

julia> CSV.write("test.csv", df);

julia> df2 = CSV.read("test.csv", DataFrame)

```

---

<div class="post-metadata">

### Author: ![Marc\_Hillocks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marc_hillocks/32/19894_2.png) [@Marc\_Hillocks](https://discourse.julialang.org/u/Marc_Hillocks)
#### Post date: [December 2, 2020, 9:20am UTC](https://discourse.julialang.org/t/how-to-use-the-csv-read-error-provide-a-valid-sink-argument/51076/10 "2020-12-02T09:20:07Z")

</div>

Thanks! This code runs, then I retried my old code right after and it works now. Thanks so much for your assistance!

---

<div class="post-metadata">

### Author: ![Skoffer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skoffer/32/378_2.png) [@Skoffer](https://discourse.julialang.org/u/Skoffer)
#### Post date: [December 2, 2020, 10:15am UTC](https://discourse.julialang.org/t/how-to-use-the-csv-read-error-provide-a-valid-sink-argument/51076/11 "2020-12-02T10:15:08Z")

</div>

Late to the party, but this line

```julia
project_data = using DataFrames; CSV.read("/Users/odionhillocks/Desktop/Project6925/Data.csv", DataFrame)

```

was split in two, due to the `;` character

```julia
project_data = using DataFrames
CSV.read("/Users/odionhillocks/Desktop/Project6925/Data.csv", DataFrame)

```

So, you read output of `using DataFrames` in `project_data` variable (which is a weird thing, suppose it was `nothing`?) and after that julia read csv file and ignore it.

If you need to use `;` symbol, you should put it into brackets

```julia
project_data = (using DataFrames; CSV.read("/Users/odionhillocks/Desktop/Project6925/Data.csv", DataFrame))

```

but there is no sense in doing it in this line of code. Also do not put `using` statements inside calculations, it’s better to import library at the beginning of the script.
