Explore Courses Blog Tutorials Interview Questions
0 votes
in BI by (17.6k points)
edited by

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



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. 

1 Answer

0 votes
by (47.2k points)
edited by
  • Headers can be printed 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




to-report quote [ #thing ]

  ifelse is-number? #thing

  [ report #thing ]

  [ report (word "\"" #thing "\"") ]


  • You would call it with

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

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

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

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

Related questions

0 votes
1 answer
asked Jul 24, 2019 in BI by Vaibhav Ameta (17.6k points)
0 votes
1 answer
asked Jul 22, 2019 in BI by Vaibhav Ameta (17.6k points)
+1 vote
1 answer
asked Oct 31, 2019 in Data Science by chandra (29.3k points)

Browse Categories