请问把CSV文件读取成DataFrame时怎么指定数据类型

在一个CSV文件中,有一列的数据是这样的
00
01
02

100
在用CSV.read读取成DataFrame时总是读取成数字,请问有没有选项使得数据强制转为字符串??

有的,指定需要的类型参数就是了

你到是告诉我啊:rofl:

多看文档。

CSV.File(file; types=Dict(:col3 => String))
CSV.File(file; types=Dict("col3" => String))
CSV.File(file; types=[String, String, String])

tst.csv

col1,col2,col3
1,2,3
4,5,invalid
6,7,8
julia> CSV.File("tst.csv")
3-element CSV.File{false}:
 CSV.Row(1): (col1 = 1, col2 = 2, col3 = "3")
 CSV.Row(2): (col1 = 4, col2 = 5, col3 = "invalid")
 CSV.Row(3): (col1 = 6, col2 = 7, col3 = "8")

julia> CSV.File("tst.csv"; typemap=Dict(Int => String))
3-element CSV.File{false}:
 CSV.Row(1): (col1 = 1.0, col2 = 2.0, col3 = "3")
 CSV.Row(2): (col1 = 4.0, col2 = 5.0, col3 = "invalid")
 CSV.Row(3): (col1 = 6.0, col2 = 7.0, col3 = "8")

julia> CSV.File("tst.csv"; types=Dict(:col1 => String))
3-element CSV.File{false}:
 CSV.Row(1): (col1 = "1", col2 = 2, col3 = "3")
 CSV.Row(2): (col1 = "4", col2 = 5, col3 = "invalid")
 CSV.Row(3): (col1 = "6", col2 = 7, col3 = "8")

julia> CSV.File("tst.csv"; types=[String, String, String])
3-element CSV.File{false}:
 CSV.Row(1): (col1 = "1", col2 = "2", col3 = "3")
 CSV.Row(2): (col1 = "4", col2 = "5", col3 = "invalid")
 CSV.Row(3): (col1 = "6", col2 = "7", col3 = "8")

julia>