如何从CSV文件导入数据并逐行将其转换为字符串?每当我尝试时,都会收到错误消息,表明它仍然是列表或列表列表。我试图复制Netlogo用户手册中给出的示例,用于读取每个刻度线一行的文件(见下文)。我创建了一个更简单的例子。谢谢!
我的代码:
extensions [CSV]
globals [date]
to setup
clear-all
file-close-all
file-open "S&PDate.csv"
set date current-date
reset-ticks
end
to go
if file-at-end? [stop]
set date current-date
tick
end
to-report current-date
file-open "S&PDate.csv"
let result csv:from-row file-read-line
while [ not file-at-end? ] [
let row csv:from-row file-read-line
set result (map result row)
]
file-close
report result
end
答案 0 :(得分:1)
Saad is right, and you may want to have a look at the asking guidelines on making an MCVE. Are you wanting string output so that your monitors look nice? If so, would this do the trick?
extensions [ csv ]
globals [ dates ]
to setup
ca
set dates csv:from-file "example_strings.csv"
reset-ticks
end
to go
if ticks < length dates [
print current-date
tick
]
end
to-report current-date
report csv:to-string ( list item ticks dates )
end