# Importing data with ambiguous dates

**URL:** <https://discourse.julialang.org/t/importing-data-with-ambiguous-dates/77391>\
**Category:** Data\
**Tags:** question, dataframes, csv\
**Created:** [March 4, 2022, 6:06am UTC](https://discourse.julialang.org/t/importing-data-with-ambiguous-dates/77391 "2022-03-04T06:06:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![George\_Githinji](https://avatars.discourse-cdn.com/v4/letter/g/e68b1a/32.png) [@George\_Githinji](https://discourse.julialang.org/u/George_Githinji)\
**Post date:** [March 4, 2022, 6:06am UTC](https://discourse.julialang.org/t/importing-data-with-ambiguous-dates/77391/1 "2022-03-04T06:06:13Z")

</div>

I have a large data-set with date columns in the format `yyyy-mm-dd`. The challenge is that some of the rows have dates that are ambiguous and contain either the `yyyy` e.g. 2019 or `yyyy-mm` e.g. `2019-09.`

I would like to import and not modify the date so that I can identify the rows with ambiguous date entries and either analyse them separately or remove them from the analysis. I am using the `CSV.jl` and `DataFrames.jl` packages to import and analyse the data.

However, after running,

```julia
data = """
              code,date
              0,2019-02
              1,2019-01
              3,2019
              4,2019-04-23
              """
"code,date\n0,2019-02\n1,2019-01\n3,2019\n4,2019-04-23\n"

```

Followed by something like this,

```julia
file = CSV.File(IOBuffer(data)) |> DataFrame
4×2 DataFrame
 Row │ code date
     │ Int64 Date
─────┼───────────────────
   1 │ 0 2019-02-01
   2 │ 1 2019-01-01
   3 │ 3 2019-01-01
   4 │ 4 2019-04-23

```

The date column “fills” to a default format (either January if the month and day are missing, or the first day of the month if just the day that is missing) and therefore I cannot tell which is which because the actual rows with the correct `2019-01-01` gets mixed up with the interpolated ones and missing dates.

I am wondering what is the best way to import the data and retain the date format and respect the date in each row and so i can later filter all entries with a complete date or ambiguous date.

---

<div class="post-metadata">

**Author:** ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)\
**Post date:** [March 4, 2022, 7:00am UTC](https://discourse.julialang.org/t/importing-data-with-ambiguous-dates/77391/2 "2022-03-04T07:00:55Z")

</div>

You can turn off type detection by using the `types` kw argument

One such way:

```julia
file = CSV.File(IOBuffer(data); types=[Int, String]) |> DataFrame
4×2 DataFrame
 Row │ code date       
     │ Int64 String     
─────┼───────────────────
   1 │ 0 2019-02
   2 │ 1 2019-01
   3 │ 3 2019
   4 │ 4 2019-04-23

```

You can even do it just for a single column

`file = CSV.File(IOBuffer(data); types=Dict("date"=>String)) |> DataFrame`  
or  
`file = CSV.File(IOBuffer(data); types=Dict(:date=>String)) |> DataFrame`

and post process the DataFrame to do what you want using filter or subset or whatever

---

<div class="post-metadata">

**Author:** ![George\_Githinji](https://avatars.discourse-cdn.com/v4/letter/g/e68b1a/32.png) [@George\_Githinji](https://discourse.julialang.org/u/George_Githinji)\
**Post date:** [March 4, 2022, 1:13pm UTC](https://discourse.julialang.org/t/importing-data-with-ambiguous-dates/77391/3 "2022-03-04T13:13:25Z")

</div>

Thanks! That worked!

---

<div class="post-metadata">

**Author:** ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)\
**Post date:** [March 4, 2022, 2:22pm UTC](https://discourse.julialang.org/t/importing-data-with-ambiguous-dates/77391/4 "2022-03-04T14:22:51Z")

</div>

could you marked it solved please - it it changes the appearance in the listings
