如何在 Julia 中导入和读取 Excel 行?
我有一个如下图所示的数据集,想要读取和提取每个单元格并将它们分配到优化模型中的参数中。例如,仅考虑一行的一部分:
ID, Min, speed, Distance, Time Latitude, Longitude
1 2506 23271 11.62968 17.7 -37.731 144.898
每一行描述一个人的信息。那么,定义一个人的字典并将所有这些放入其中是不是更好?或者定义一个元组更好?数组(如下所示)?
for i in 1:n_people
person_id = i
push!(requests, Request(ID[i], Min[i], speed[i], Distance[i], Latitude[i], Longitude[i]))
end
无论如何,我如何访问(提取)该人的距离? 我的意思是,我的模型中需要有一组人,例如 people[i]
然后对于每个人将它们连接到他们的信息(模型参数),例如人的“i”距离、速度......然后将它们与人j
进行比较代码>. 最好的方法是什么?
I have a dataset like the following picture and want to read and extract each cell and assign them into parameters in an optimization model. For example, considering only one part of a row:
ID, Min, speed, Distance, Time Latitude, Longitude
1 2506 23271 11.62968 17.7 -37.731 144.898
Every row depicts a persons' information. So, is it better to define a dictionary of person and put all these into that? Or is it better to define a tuple? Arrays(like below)?
for i in 1:n_people
person_id = i
push!(requests, Request(ID[i], Min[i], speed[i], Distance[i], Latitude[i], Longitude[i]))
end
In any case, how can I access (extract), let's say, distance for that person?
I mean, I need to have a set of people in my model likepeople[i]
and then for each of these connect them to their information (model parameters) like person's 'i' distance, speed,... and then compare them with person j
.
What is the best way to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 JuMP 与输入数据的格式无关,因此答案是:这取决于您想用它做什么。选择对您最有意义的内容。
有一些与数据相关的教程,介绍如何将数据读入 DataFrame 并使用它来创建 JuMP 变量和约束。阅读这些内容是下一步:
https://jump.dev/JuMP .jl/stable/tutorials/getting_started/getting_started_with_data_and_plotting/
https://jump.dev/JuMP.jl/stable/tutorials/linear/diet /
Since JuMP is agnostic to the format of the input data, the answer is: it depends on what you want to do with it. Pick whatever makes the most sense to you.
There are a few data related tutorials that address how to read data into a DataFrame and use that to create JuMP variables and constraints. Reading those is a good next step:
https://jump.dev/JuMP.jl/stable/tutorials/getting_started/getting_started_with_data_and_plotting/
https://jump.dev/JuMP.jl/stable/tutorials/linear/diet/