我正在尝试将CSV文件读入Julia。当我在Excel中打开该文件时,它是一个199x7的数字矩阵。我使用以下代码创建变量Xrel:
Xrel = CSV.read(joinpath(data_path,"Xrel.csv"), header=false)然而,当我尝试这样做时,Julia产生了:
"MethodError: Cannot 'convert' an object of type Bool to an object of type String."
为了节省空间,在前面的代码中定义了data_path。我已经检查了我的路径,并在R中没有问题地打开了CSV -只有在Julia中我才有问题。
我很困惑,为什么Julia说我的数据是布尔型的,而它是一个数字矩阵?我如何解决这个问题才能读入我的CSV文件?
谢谢!!
发布于 2021-02-06 00:57:06
我认为您应该在CSV.read()中使用CSV.File()或添加一个接收器变量
CSV.File(joinpath(data_path,"Xrel.csv"), header=false)
# or with a DataFrame as sink
using DataFrames
CSV.read(joinpath(data_path,"Xrel.csv"), DataFrame, header=false)从文档中:
?CSV.read
CSV.read(source, sink::T; kwargs...) => T
Read and parses a delimited file, materializing directly using the sink function.
CSV.read supports all the same keyword arguments as CSV.File.https://stackoverflow.com/questions/66064126
复制相似问题