0

I have a tech.tablesaw.api.Table that got filled by SQL Result Set. But I want to overwrite one of the columns with other values before running SMILE (the setValue method below doesn't exist, but I'm looking for something like that). Is the Table object readonly? Or is there a way to do this? Thanks!

    for(int r=0; r < theTable.rowCount(); r++) {
        theTable.row(r).column("last_name").setValue("Smith");
    }
fandang
  • 605
  • 1
  • 6
  • 14

1 Answers1

1

There are several ways to set values in columns. One approach is to use a Row object to iterate over the table:

for (Row row : theTable) {
    row.setString("last_name", "Smith");
}

On the other hand, you can update the column directly.

StringColumn lastName = theTable.stringColumn("last_name");
for (int r = 0; r < theTable.rowCount(); r++) {
    lastName.set(r, "Smith");
}

There are other methods that can be used to update the column conditionally, using values from the same row in another column, and so on.

L. Blanc
  • 2,150
  • 2
  • 21
  • 31
  • 1
    Thank you - My Row object in tablesaw-core-0.30.3 didn't have a setString method, but the 2nd part of your answer worked great, thanks! – fandang Aug 02 '19 at 20:28