将CSV文件读入Julia DataFrame

3
当我按照这篇博客文章中所述尝试将csv文件导入Julia DataFrame时,得到了意外的结果。 DataFrame()把每个CSV.Row放入一个单元格而不是每个字段。由于CSV.Row对象是正确的,因此CSV.jl似乎不是问题。有人看到我漏掉了什么吗? example.csv
col1,col2,col3
1,2,3
2,3,5
0,1,1

using CSV
using DataFrames

DataFrame(CSV.File("example.csv"))

结果

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)

期望结果

col1 col2 col3
1 2 3
2 3 5
0 1 1

编辑

我使用的版本是:

CSV v0.8.3

DataFrames v0.13.1

1个回答

1

请确保您正在使用最新的DataFrames.jl 0.22.5和CSV.jl 0.8.3版本。在它们下面,您可以得到您要求的内容:

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 
─────┼─────────────────────
   11      2      3
   22      3      5
   30      1      1

谢谢您的快速回复。我的DataFrames版本确实是问题所在。 - Jonas

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接