【问题标题】:Netlogo Export/Tableau issuesNetlogo 导出/Tableau 问题
【发布时间】:2014-03-17 18:16:31
【问题描述】:

目前我正在尝试将我的数据从 Netlogo 导出到 CSV 文件,然后使用以下代码将其加载到 Tableau 中..

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

遇到麻烦的地方是,当我将数据加载到画面中时,它没有正确获取度量/维度。 Netlogo 中是否有一种方法可以在将我的每一行/列导出到 CSV 文件之前指定它们的标题?

【问题讨论】:

    标签: csv netlogo tableau-api


    【解决方案1】:

    这个问题是在 NetLogo 用户上提出并回答的。下面复制了 James Steiner 的答案,并更正了代码中的一些拼写错误。真的很优雅。


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

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

    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
    

    你可以用

    来调用它
    write-csv "myfilename.csv" ["label1" "label2" "label3"]
    

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

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

    写入一行数据 - 在本例中是一个数字、一个字符串和另一个数字。

    【讨论】:

    • 这里是 netlogo-users 上的主题链接:groups.yahoo.com/neo/groups/netlogo-users/conversations/…。 Mike,如果您在多个论坛中提出相同的问题,最好这样说,并尽可能提供链接,这样人们就不会浪费时间在一个论坛上回答已经在另一个论坛上解决的问题。跨度>
    猜你喜欢
    • 2016-09-23
    • 1970-01-01
    • 1970-01-01
    • 2019-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-18
    相关资源
    最近更新 更多