我想将股票历史数据加载并读取到netlogo中,我发现how to read a .CSV file with netlogo非常有帮助。
但是,为了实现我所需要的,我仍然需要进入fileList
的每个元素列表(参见上面的链接),并提取元素列表的每个元素并将它们存储到不同的列表中如dates
、openPrices
、highPrices
等。
谁能告诉我如何实现它?或者指出一些代码示例也非常有帮助。我刚刚开始学习netlogo,所以还有很多东西需要补。
非常感谢!
股票历史数据如下所示
2015/12/15, 12, 12.9, 11.99, 12.5, 10000
2015/12/16, 12.1, 13.9, 11.99, 12.8, 11000
globals[eachLine dates openPrices highPrices lowPrices closePrices volumes]
to openFile
file-open "jqr.txt"
set dates []
set openPrices []
set highPrices []
set lowPrices []
set closePrices []
set volumes []
set fileList []
while [not file-at-end?] [
set csv file-read-line
set csv word csv "," ; add comma for loop termination
let mylist [] ; list of values
while [not empty? csv]
[
let $x position "," csv
let $item substring csv 0 $x ; extract item
carefully [set $item read-from-string $item][] ; convert if number
set mylist lput $item mylist ; append to list
set csv substring csv ($x + 1) length csv ; remove item and comma
]
set fileList lput mylist fileList
]
;; ??????
foreach fileList
show fileList
file-close
end
最佳答案
尝试 NetLogo 的 csv extension .
关于csv - 如何将 CSV 文件中的股票数据读取到 netlogo 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34313328/