# Load and reformatting CSV file

**URL:** <https://discourse.julialang.org/t/load-and-reformatting-csv-file/69518>\
**Category:** New to Julia\
**Tags:** strings, dataframes, csv, parsing, io\
**Created:** [October 10, 2021, 5:24pm UTC](https://discourse.julialang.org/t/load-and-reformatting-csv-file/69518 "2021-10-10T17:24:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rami](https://avatars.discourse-cdn.com/v4/letter/r/9d8465/32.png) [@rami](https://discourse.julialang.org/u/rami)\
**Post date:** [October 10, 2021, 5:24pm UTC](https://discourse.julialang.org/t/load-and-reformatting-csv-file/69518/1 "2021-10-10T17:24:11Z")

</div>

Hello,

I am trying to load a CSV file from a Github rep, reformat, and store it as DataFrame obj. Here is what I tried:

```julia
using CSV, HTTP, DataFrames
url = "https://raw.githubusercontent.com/RamiKrispin/coronavirus/master/csv/coronavirus.csv"
http_response = HTTP.get(url)
file = CSV.File(http_response.body)
df = DataFrame(file)

```

Here is the output I am getting:

```julia
julia> df
514572×7 DataFrame
│ Row │ date │ province │ country │ lat │ long │ type │ cases │
│ │ Dates.Date │ String63 │ String63 │ String15 │ String15 │ String15 │ String15 │
├────────┼────────────┼──────────┼──────────┼────────────┼───────────┼───────────┼──────────┤
│ 1 │ 2020-01-22 │ Alberta │ Canada │ 53.9333 │ -116.5765 │ confirmed │ 0 │
│ 2 │ 2020-01-23 │ Alberta │ Canada │ 53.9333 │ -116.5765 │ confirmed │ 0 │
│ 3 │ 2020-01-24 │ Alberta │ Canada │ 53.9333 │ -116.5765 │ confirmed │ 0 │
│ 4 │ 2020-01-25 │ Alberta │ Canada │ 53.9333 │ -116.5765 │ confirmed │ 0 │
│ 5 │ 2020-01-26 │ Alberta │ Canada │ 53.9333 │ -116.5765 │ confirmed │ 0 │
│ 6 │ 2020-01-27 │ Alberta │ Canada │ 53.9333 │ -116.5765 │ confirmed │ 0 │
⋮
│ 514566 │ 2021-10-02 │ NA │ Zimbabwe │ -19.015438 │ 29.154857 │ recovered │ NA │
│ 514567 │ 2021-10-03 │ NA │ Zimbabwe │ -19.015438 │ 29.154857 │ recovered │ NA │
│ 514568 │ 2021-10-04 │ NA │ Zimbabwe │ -19.015438 │ 29.154857 │ recovered │ NA │
│ 514569 │ 2021-10-05 │ NA │ Zimbabwe │ -19.015438 │ 29.154857 │ recovered │ NA │
│ 514570 │ 2021-10-06 │ NA │ Zimbabwe │ -19.015438 │ 29.154857 │ recovered │ NA │
│ 514571 │ 2021-10-07 │ NA │ Zimbabwe │ -19.015438 │ 29.154857 │ recovered │ NA │
│ 514572 │ 2021-10-08 │ NA │ Zimbabwe │ -19.015438 │ 29.154857 │ recovered │ NA │

```

How can I modify the `cases` column from string to integer? It classifies it as string as it has missing values classify as `NA`. I was trying to use this:

```julia
file = CSV.File(http_response.body, null=“NA”)

```

but this argument is not available for the `CSV.File` function.

Any suggestions?

Also, any shorter way to load CSV file from URL?

Thanks!

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [October 10, 2021, 6:15pm UTC](https://discourse.julialang.org/t/load-and-reformatting-csv-file/69518/2 "2021-10-10T18:15:08Z")

</div>

> [@rami](#):
>
> any shorter way to load CSV file from URL

You can use `download()`:

```julia
using CSV, DataFrames
url = "https://raw.githubusercontent.com/RamiKrispin/coronavirus/master/csv/coronavirus.csv"
file = CSV.File(download(url))
df = DataFrame(file)

```

---

<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:** [October 10, 2021, 6:17pm UTC](https://discourse.julialang.org/t/load-and-reformatting-csv-file/69518/3 "2021-10-10T18:17:36Z")

</div>

It seems like you are using some pretty old versions of things. The keyword argument should be `missingstring = "NA"`. But I would suggest updating to the latest versions of packages first.

---

<div class="post-metadata">

**Author:** ![danielw2904](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielw2904/32/10890_2.png) [@danielw2904](https://discourse.julialang.org/u/danielw2904)\
**Post date:** [October 10, 2021, 7:50pm UTC](https://discourse.julialang.org/t/load-and-reformatting-csv-file/69518/4 "2021-10-10T19:50:01Z")

</div>

You can add the `types` Argument which takes a `Dict(colname=> type)`. But I think once you us `missingstring`. It’ll parse automatically

---

<div class="post-metadata">

**Author:** ![danielw2904](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielw2904/32/10890_2.png) [@danielw2904](https://discourse.julialang.org/u/danielw2904)\
**Post date:** [October 10, 2021, 7:51pm UTC](https://discourse.julialang.org/t/load-and-reformatting-csv-file/69518/5 "2021-10-10T19:51:03Z")

</div>

I think the version is new and the argument incorrect ( since it is using the new inline string)

---

<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:** [October 10, 2021, 8:32pm UTC](https://discourse.julialang.org/t/load-and-reformatting-csv-file/69518/6 "2021-10-10T20:32:44Z")

</div>

Ah good catch. But the DataFrames.jl is old.

---

<div class="post-metadata">

**Author:** ![rami](https://avatars.discourse-cdn.com/v4/letter/r/9d8465/32.png) [@rami](https://discourse.julialang.org/u/rami)\
**Post date:** [October 10, 2021, 11:10pm UTC](https://discourse.julialang.org/t/load-and-reformatting-csv-file/69518/7 "2021-10-10T23:10:12Z")

</div>

Thanks all for the answers! I added the `missingstring= "NA"` argument and it works:

```julia
file = CSV.File(download(url), missingstring= "NA")
df = DataFrame(file)

df
515394×7 DataFrame
│ Row │ date │ province │ country │ lat │ long │ type │ cases │
│ │ Dates.Date │ String63? │ String63 │ Float64? │ Float64? │ String15 │ Int64? │
├────────┼────────────┼───────────┼──────────┼──────────┼──────────┼───────────┼─────────┤
│ 1 │ 2020-01-22 │ Alberta │ Canada │ 53.9333 │ -116.576 │ confirmed │ 0 │
│ 2 │ 2020-01-23 │ Alberta │ Canada │ 53.9333 │ -116.576 │ confirmed │ 0 │
│ 3 │ 2020-01-24 │ Alberta │ Canada │ 53.9333 │ -116.576 │ confirmed │ 0 │
│ 4 │ 2020-01-25 │ Alberta │ Canada │ 53.9333 │ -116.576 │ confirmed │ 0 │
│ 5 │ 2020-01-26 │ Alberta │ Canada │ 53.9333 │ -116.576 │ confirmed │ 0 │
│ 6 │ 2020-01-27 │ Alberta │ Canada │ 53.9333 │ -116.576 │ confirmed │ 0 │
⋮
│ 515388 │ 2021-10-03 │ missing │ Zimbabwe │ -19.0154 │ 29.1549 │ recovered │ missing │
│ 515389 │ 2021-10-04 │ missing │ Zimbabwe │ -19.0154 │ 29.1549 │ recovered │ missing │
│ 515390 │ 2021-10-05 │ missing │ Zimbabwe │ -19.0154 │ 29.1549 │ recovered │ missing │
│ 515391 │ 2021-10-06 │ missing │ Zimbabwe │ -19.0154 │ 29.1549 │ recovered │ missing │
│ 515392 │ 2021-10-07 │ missing │ Zimbabwe │ -19.0154 │ 29.1549 │ recovered │ missing │
│ 515393 │ 2021-10-08 │ missing │ Zimbabwe │ -19.0154 │ 29.1549 │ recovered │ missing │
│ 515394 │ 2021-10-09 │ missing │ Zimbabwe │ -19.0154 │ 29.1549 │ recovered │ missing │

```
