csvfilenetlogo

Why do I get an error when loading my .csv data into Netlogo?


I have a .csv file with speeds in km/h that I have loading into my model and it works fine. But I need to change the info in the model and my file to m/s. When I open the .csv and insert the changes, without changing anything else (e.g. 10 km/h changed to 2.77778 m/s), I get the error:

Can't find element 1 of the list [Downhill,"0 > slope ≤ 2,5",2.77778,478.4,621.9,813.2,0,0], which is only of length 1. error while observer running ITEM called by (anonymous command: [ line -> set emission-data lput list item 0 line item 1 line item 2 line item 3 line item 4 line item 5 line item 6 line item 7 line emission-data ]) called by procedure LOAD-EMISSIONS-DATA called by procedure SETUP
called by Button 'Setup'

My code has file loading as:

   to load-emissions-data
  set emission-data []
  let file csv:from-file "emissions_table_ms.csv"
  foreach file 
  [
    line ->
    set emission-data lput (list (item 0 line) ;; movement-status
                                 (item 1 line) ;; slope
                                 (item 2 line) ;; speed
                                 (item 3 line) ;; ICE-new
                                 (item 4 line) ;; ICE-middle
                                 (item 5 line) ;; ICE-old
                                 (item 6 line) ;; hybrid
                                 (item 7 line)) ;; ev
                     emission-data
  ]
end

As far as I can see, I'm only changing targeted values in the .csv file, saving it in the same format and nothing else. I need help solving this error.


Solution

  • I would guess that your .csv file got damaged when you edited it to change the speed units. Excel is especially good at ruining .csv files. For example, if you save a file as "CSV UTF-8" in Excel (instead of "CSV"), NetLogo won't be able to read it. If you have a European computer, Excel may save your file with ";" instead of commas between fields.

    Try opening the .csv file in a plain text editor (like Notepad++), make sure it looks OK or fix it, and save it as a plain text file. It might help to look up the .CSV standard (e.g., https://en.wikipedia.org/wiki/Comma-separated_values#Basic_rules )