【发布时间】:2015-12-16 22:16:01
【问题描述】:
我想将股票历史数据加载并读取到 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
【问题讨论】: