Netlogo导出/ Tableau问题 [英] Netlogo Export/Tableau issues

查看:239
本文介绍了Netlogo导出/ Tableau问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我玩的是将我的数据从Netlogo导出到CSV文件,然后使用以下代码将其加载到Tableau。

 到写结果到文件
;如果没有写入然后停止
如果为空?结果文件[stop]
;打开文件
file-open结果文件

;写入文件
file-print(word Days-passed,num-susceptible,num-infected,num-recovered)
;关闭文件
file-close
end

我将数据加载到表格中,但未正确选取度量/维度。在Netlogo中有没有办法在导出到CSV文件之前指定每个行/列的标题?任何人都有使用tableau和Netlogo的任何经验,我真的很感谢一些帮助。

解决方案

NetLogo用户。詹姆斯·斯坦纳的答案复制如下,一些错别字在代码纠正。非常优雅。






您可以在设置期间将标题打印到结果文件中!



您可能想要创建一个子例程来处理所有写入文件,因此您不必重复代码:

  to write-csv [#filename #items] 
;; #it​​ems是要写入的数据(或标头!)的列表。
if is-list? #it​​ems不是空的? #it​​ems
[file-open #filename
;;引用非数字项
set #items map quote #items
;;打印项目
;;如果只有一个项目,打印它。
ifelse length #items = 1 [file-print first #items]
[file-print reduce [(word?1,?2)] #items]
;;特写
file-close
]
end

to-report quote [#thing]
ifelse is-number? #thing
[report #thing]
[report(word\#thing\)]
end
/ pre>




您可以使用

命名

  write-csvmyfilename.csv[label1label2label3] 

在设置例程中写列标题,然后

  write-csvmyfilename.csv 10.0sometext20.3] 

写一行数据 - ,和另一个数字。


Currently I'm playing around with exporting my data from Netlogo to a CSV file and then loading it into Tableau with the following code..

to write-result-to-file
  ; if nothing to write then  stop
  if empty? Result-File [stop]
  ; Open file
  file-open Result-File

  ; Write into the file
  file-print (word Days-passed "," num-susceptible "," num-infected "," num-recovered)
  ; Close file
  file-close
end

Where am running into trouble is when I load the data into tableau it isn't properly picking up the measures/dimensions. Is there a way in Netlogo to specify the headers of each of my rows/columns before they are exported to the CSV file? Is anyone has any experience using tableau and Netlogo I'd really appreciate some help.

解决方案

This question was asked and answered over on NetLogo Users. James Steiner's answer is copied below, with a few typos in the code corrected. It's really quite elegant.


You can print the headers to your results-file during setup!

You might want to make a subroutine to handle all writing to the file, so you don't have to repeat code:

to write-csv [ #filename #items ]
  ;; #items is a list of the data (or headers!) to write.
  if is-list? #items and not empty? #items
  [ file-open #filename
  ;; quote non-numeric items
  set #items map quote #items
  ;; print the items
  ;; if only one item, print it.
  ifelse length #items = 1 [ file-print first #items ]
  [file-print reduce [ (word ?1 "," ?2) ] #items]
  ;; close-up
  file-close
  ]
end

to-report quote [ #thing ]
  ifelse is-number? #thing
  [ report #thing ]
  [ report (word "\"" #thing "\"") ]
end


You would call it with

write-csv "myfilename.csv" ["label1" "label2" "label3"]

to write the column headers in your setup routine, and then

write-csv "myfilename.csv" [10.0 "sometext" 20.3]

to write a row of data - in this case a number, a string, and another number.

这篇关于Netlogo导出/ Tableau问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆