如何在 Julia 中导入和读取 Excel 行?

发布于 2025-01-13 22:06:35 字数 723 浏览 1 评论 0原文

我有一个如下图所示的数据集,想要读取和提取每个单元格并将它们分配到优化模型中的参数中。例如,仅考虑一行的一部分:

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 like
people[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?

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谎言月老 2025-01-20 22:06:35

由于 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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文