Array of Strings vs Table for Data Visualization

edited December 2013 in Programming Questions

Hi all,

I'm beginning to use Processing for a series of visualizations and I want to head in with some best practices. Looking through the documentation, some tutorials and other examples, it seems the main two ways to handle data are as arrays of strings and tables. Are there specific benefits of one approach or a generally accepted better option?

I would like to handle csv files, ranging in size from 30-400 pieces of data. Tables seem to be better for this and easier to export from Excel, but the lack of methods dealing with columns is worrying.

Example string array:

int[] data;
String[] steps = loadStrings("data.txt");
// Convert string into an array of intetegers, comma delimited
data = int(split(steps[0], ','));

versus a table implementation:

Table table = loadTable("data.csv", "header");
TableRow data = table.getRow(0);

Answers

  • edited December 2013
    final Table lines = loadTable("data.csv");
    
    for ( TableRow rows: lines.rows() ) {
      for ( int col = 0, num = rows.getColumnCount(); col != num; 
      print(rows.getString(col++) + "   ") );
    
      println('\n');
    }
    
    exit();
    
  • I'm sorry, I don't quite understand your answer. What's going on in lines 4 and 5 and how is it better than a normal for loop?

  • edited December 2013 Answer ✓

    It's just an example I had here to iterate on each element of each row from a Table.
    I've found that would be useful?! :-SS

    You've mentioned that it lacked methods to deal w/ columns. But fortunately, that isn't true! :P
    There's a helper class called TableRow which we can get an iterator for it outta Table's rows() method! *-:)

    From there, we can issue getColumnCount() in order to know how many columns that particular row got!

    Then, getString() gets us its content. We can choose by column's index as I did there or by column's title!

    And about lines 4 & 5, they're actually 1 for () statement split in 2 adjacent lines! :-\"

    More about TableRow:
    http://processing.org/reference/TableRow.html

  • Oh, that does seem very useful. My next question is how do I handle the data in that column? I can't seem to figure out what variable I would use to create things like bar charts.

  • So sorry, but that is as far as my knowledge reaches yet! :o3
    I've left many links to Processing's reference about it. Just hover your mouse over there! O:-)

    In my little understanding, I only see setString/Float/Int() & getString/Float/Int() there!
    I don't think we can place a bar graph there!!! @-)

Sign In or Register to comment.