IllegalArgumentException: This table has no column named ' '

Hello there!

So, I have the following csv table:

Jahr;Insgesamt
2022;17392
2021;18037
2020;18515
2019;18351
2018;17695
2017;16745
2016;16088
2015;15083
2014;14316
2013;13241
2012;12158
2011;11147

And this is my code:


Table table;

void setup() {

  table = loadTable("data.csv", "header");

  println(table.getColumnCount() + " total Columns in table");

  for (TableRow row : table.rows()) {

    int years = row.getInt("Jahr");
    int total = row.getInt("Insgesamt");

    println("In the year " + years + " there were " + total + " students in total.");
  }

}

Even though in my data it clearly says “Jahr” and “Insgesamt”, somehow it’s not recognizing the names, and it’s saying there’s only 1 column when there are actually two.

I think columns need to be separated with , not with ;

see loadTable() / Reference / Processing.org

1 Like

I had converted my excel data to csv and that’s how it got converted. So to fix it, I opened the csv in notes, copy-paste each row in a single box in excel (one above the other) and replaced “;” with “,”.
Thank you very much for your help!

1 Like

unrelated to the , / ; problem: A small Sketch to parse a String to a table:

//

String [] list = {
  "Jahr,Insgesamt", 
  "2022,17392", 
  "2021,18037", 
  "2020,18515", 
  "2019,18351", 
  "2018,17695", 
  "2017,16745", 
  "2016,16088", 
  "2015,15083", 
  "2014,14316", 
  "2013,13241", 
  "2012,12158", 
  "2011,11147"
};

Table table;

void setup() {
  size(200, 100); 

  table = parseToTable(list);

  println(table.getColumnCount() + " total Columns in table");

  for (TableRow row : table.rows()) {

    int years = row.getInt("Jahr");
    int total = row.getInt("Insgesamt");

    println("In the year " + years + " there were " + total + " students in total.");
  }
}

// -----------------------------------------------------------------------------------------------------------------------

Table parseToTable(String[] listLocal) {

  Table tableLocal = new Table();

  tableLocal.addColumn("Jahr");
  tableLocal.addColumn("Insgesamt");

  for (String s1 : listLocal) {
    String[] s2=split(s1, ",");
    if (isNotANumber(s2[0])) {
      println("skipped "
        + s1
        + " (not a number) " );
      continue;
    }
    if (s2.length != 2) {
      println("skipped "
        + s1
        + " (column count != 2)");
      continue;
    }

    TableRow newRow = tableLocal.addRow();
    newRow.setString("Jahr", s2[0]);
    newRow.setString("Insgesamt", s2[1]);
  }//for 

  //  table = loadTable("data.csv", "header");

  return tableLocal;
}//func

boolean isNotANumber(String s ) {
  return 
    ! (s.charAt(0) > '0' && s.charAt(0) < '9');
}

//

1 Like