[英]parse(Float64,trip)--error:cannot parse trip as Float64
The code that I use: 我使用的代码:
for trip in df[:Polyline]
trip = parse(Float64,trip) |> eval
end
The error I get: 我得到的错误:
error:cannot parse trip as Float64
错误:无法将行程解析为Float64
trip is a string like [[-8.764913,6.461675],[7.461345,9.754319]]
trip是一个类似
[[-8.764913,6.461675],[7.461345,9.754319]]
的字符串
You did not provide a minimal working example in your question (try to edit it!). 您没有在问题中提供最低限度的工作示例(尝试对其进行编辑!)。 However this is what I understand that you need.
但是,这就是我所需要的。
Suppose you have a String
: 假设您有一个
String
:
trip = "[[-8.7,6.4],[7.4,9.7],[3.4,2.1]]"
Use JSON.jl
package to parse it: 使用
JSON.jl
包对其进行解析:
julia> using JSON
julia> JSON.parse(trip)
3-element Array{Any,1}:
Any[-8.7, 6.4]
Any[7.4, 9.7]
Any[3.4, 2.1]
You might prefer to have an Array
of Float64
s instead: 您可能更喜欢使用
Float64
Array
:
julia> Vector{Float64}.(JSON.parse(trip))
3-element Array{Array{Float64,1},1}:
[-8.7, 6.4]
[7.4, 9.7]
[3.4, 2.1]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.