When I try to import a csv file into a Julia DataFrame as descibed in this blogpost I get unexpected results.
DataFrame() puts each CSV.Row into a cell instead of each field. CSV.jl doesn't seem to be the problem, since the CSV.Row objects are correct. Does somebody see what I'm missing here?
example.csv
col1,col2,col3
1,2,3
2,3,5
0,1,1
using CSV
using DataFrames
DataFrame(CSV.File("example.csv"))
result
| x1 | x2 | x3 |
|---|---|---|
| CSV.Row: (col1 = 1, col2 = 2, col3 = 3) | CSV.Row: (col1 = 2, col2 = 3, col3 = 5) | CSV.Row: (col1 = 0, col2 = 1, col3 = 1) |
expected result
| col1 | col2 | col3 |
|---|---|---|
| 1 | 2 | 3 |
| 2 | 3 | 5 |
| 0 | 1 | 1 |
Edit
I was using:
CSV v0.8.3
DataFrames v0.13.1
Make sure you are using the latest DataFrames.jl 0.22.5 and CSV.jl 0.8.3. Under them I get what you ask for:
julia> str = """col1,col2,col3
1,2,3
2,3,5
0,1,1""";
julia> DataFrame(CSV.File(IOBuffer(str)))
3×3 DataFrame
Row │ col1 col2 col3
│ Int64 Int64 Int64
─────┼─────────────────────
1 │ 1 2 3
2 │ 2 3 5
3 │ 0 1 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With