# Loading a csvfile using CSVFiles

**URL:** https://discourse.julialang.org/t/loading-a-csvfile-using-csvfiles/17305
**Category:** General Usage
**Created:** [November 8, 2018, 2:34pm UTC](https://discourse.julialang.org/t/loading-a-csvfile-using-csvfiles/17305 "2018-11-08T14:34:41Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Peter\_Staab](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peter_staab/32/5874_2.png) [@Peter\_Staab](https://discourse.julialang.org/u/Peter_Staab)
#### Post date: [November 8, 2018, 2:34pm UTC](https://discourse.julialang.org/t/loading-a-csvfile-using-csvfiles/17305/1 "2018-11-08T14:34:41Z")

</div>

I have a file with a date in the form mm/dd/yy and my guess is that it is interpreting it in dd/mm/yy format. I’ve been using CSVFiles to do this with the load command and have tried the following:

```julia
load("test.csv",colparsers=[5=>dateformat"mm/dd/yy"])

```

since it is the 5th column. I’ve also tried the column name as well am getting the following error:

```julia
MethodError: no method matching tofield(::Pair{Symbol,DateFormat{Symbol("mm/dd/yy"),
Tuple{Dates.DatePart{'m'},Dates.Delim{Char,1},Dates.DatePart{'d'},
Dates.Delim{Char,1},Dates.DatePart{'y'}}}}, ::TextParse.LocalOpts)

```

so obviously I’m not calling this correctly, but I can’t find documentation on this, nor am able to figure it out from the source code.

Here’s the first lines of that file:

```julia
Athlete,Age,Country,Year,Closing Ceremony Date,Sport,Gold Medals,Silver Medals,Bronze Medals,Total Medals
Michael Phelps,23,United States,2008,8/24/08,Swimming,8,0,0,8
Michael Phelps,19,United States,2004,8/29/04,Swimming,6,0,2,8
Michael Phelps,27,United States,2012,8/12/12,Swimming,4,2,0,6
Natalie Coughlin,25,United States,2008,8/24/08,Swimming,1,2,3,6

```

---

<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 8, 2018, 4:22pm UTC](https://discourse.julialang.org/t/loading-a-csvfile-using-csvfiles/17305/2 "2018-11-08T16:22:31Z")

</div>

I know CSVFiles/TextParse.jl have been doing some refactoring lately, so probably just a missing method somewhere. In the mean time, you could use CSV.jl like:

```julia
julia> df = CSV.read("/Users/jacobquinn/Downloads/discourse.csv", dateformat="mm/dd/yy", transforms=Dict("Closing Ceremony Date"=>x->x + Dates.Year(2000)))
4×10 DataFrames.DataFrame. Omitted printing of 1 columns
│ Row │ Athlete │ Age │ Country │ Year │ Closing Ceremony Date │ Sport │ Gold Medals │ Silver Medals │ Bronze Medals │
│ │ String │ Int64 │ String │ Int64 │ Date │ String │ Int64 │ Int64 │ Int64 │
├─────┼──────────────────┼───────┼───────────────┼───────┼───────────────────────┼──────────┼─────────────┼───────────────┼───────────────┤
│ 1 │ Michael Phelps │ 23 │ United States │ 2008 │ 2008-08-24 │ Swimming │ 8 │ 0 │ 0 │
│ 2 │ Michael Phelps │ 19 │ United States │ 2004 │ 2004-08-29 │ Swimming │ 6 │ 0 │ 2 │
│ 3 │ Michael Phelps │ 27 │ United States │ 2012 │ 2012-08-12 │ Swimming │ 4 │ 2 │ 0 │
│ 4 │ Natalie Coughlin │ 25 │ United States │ 2008 │ 2008-08-24 │ Swimming │ 1 │ 2 │ 3 │

```

---

<div class="post-metadata">

### Author: ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)
#### Post date: [November 12, 2018, 12:38am UTC](https://discourse.julialang.org/t/loading-a-csvfile-using-csvfiles/17305/3 "2018-11-12T00:38:59Z")

</div>

You need to pass a `Dict` to `colparsers`, not a vector, in this case:

```julia
load("test.csv",colparsers=Dict(5=>dateformat"mm/dd/yy"))

```

You would use a vector when you want to specify just all column parsers, not as `Pair`s, but just as a list of parsers.

---

<div class="post-metadata">

### Author: ![davidanthoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidanthoff/32/223493_2.png) [@davidanthoff](https://discourse.julialang.org/u/davidanthoff)
#### Post date: [November 12, 2018, 1:32am UTC](https://discourse.julialang.org/t/loading-a-csvfile-using-csvfiles/17305/4 "2018-11-12T01:32:05Z")

</div>

I just realized that this will still not give you what you want: it will parse the years as the year `0008` etc… That seems a weird default (to me) in the julia base date parsing story… The python/posix approach to parsing two digit year numbers seems much more useful to me. It also seems to me that it would be super helpful if one could specify in the `dateformat` string how two digit years should be handled (given that I would guess that the current behavior is almost never very useful).
