Java Code Examples for tech.tablesaw.api.Table#stringColumn()

The following examples show how to use tech.tablesaw.api.Table#stringColumn() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Stats.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
public Table asTableComplete() {
  Table t = asTable();

  StringColumn measure = t.stringColumn("Measure");
  DoubleColumn value = t.doubleColumn("Value");

  measure.append("Sum of Squares");
  value.append(sumOfSquares());

  measure.append("Sum of Logs");
  value.append(sumOfLogs());

  measure.append("Population Variance");
  value.append(populationVariance());

  measure.append("Geometric Mean");
  value.append(geometricMean());

  measure.append("Quadratic Mean");
  value.append(quadraticMean());

  measure.append("Second Moment");
  value.append(secondMoment());

  return t;
}
 
Example 2
Source File: Stats.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
public Table asTableComplete() {
  Table t = asTable();

  StringColumn measure = t.stringColumn("Measure");
  DoubleColumn value = t.doubleColumn("Value");

  measure.append("Sum of Squares");
  value.append(sumOfSquares());

  measure.append("Sum of Logs");
  value.append(sumOfLogs());

  measure.append("Population Variance");
  value.append(populationVariance());

  measure.append("Geometric Mean");
  value.append(geometricMean());

  measure.append("Quadratic Mean");
  value.append(quadraticMean());

  measure.append("Second Moment");
  value.append(secondMoment());

  return t;
}
 
Example 3
Source File: DataFrameJoiner.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
/** Create a reverse index for a given column. */
private Index indexFor(Table table, int colIndex) {
  ColumnType type = table.column(colIndex).type();
  if (type instanceof DateColumnType) {
    return new IntIndex(table.dateColumn(colIndex));
  } else if (type instanceof DateTimeColumnType) {
    return new LongIndex(table.dateTimeColumn(colIndex));
  } else if (type instanceof InstantColumnType) {
    return new LongIndex(table.instantColumn(colIndex));
  } else if (type instanceof TimeColumnType) {
    return new IntIndex(table.timeColumn(colIndex));
  } else if (type instanceof StringColumnType || type instanceof TextColumnType) {
    return new StringIndex(table.stringColumn(colIndex));
  } else if (type instanceof IntColumnType) {
    return new IntIndex(table.intColumn(colIndex));
  } else if (type instanceof LongColumnType) {
    return new LongIndex(table.longColumn(colIndex));
  } else if (type instanceof ShortColumnType) {
    return new ShortIndex(table.shortColumn(colIndex));
  } else if (type instanceof BooleanColumnType) {
    return new ByteIndex(table.booleanColumn(colIndex));
  } else if (type instanceof DoubleColumnType) {
    return new DoubleIndex(table.doubleColumn(colIndex));
  } else if (type instanceof FloatColumnType) {
    return new FloatIndex(table.floatColumn(colIndex));
  }
  throw new IllegalArgumentException("Joining attempted on unsupported column type " + type);
}
 
Example 4
Source File: DataFrameJoiner.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
/** Create a reverse index for a given column. */
private Index indexFor(Table table, int colIndex) {
  ColumnType type = table.column(colIndex).type();
  if (type instanceof DateColumnType) {
    return new IntIndex(table.dateColumn(colIndex));
  } else if (type instanceof DateTimeColumnType) {
    return new LongIndex(table.dateTimeColumn(colIndex));
  } else if (type instanceof InstantColumnType) {
    return new LongIndex(table.instantColumn(colIndex));
  } else if (type instanceof TimeColumnType) {
    return new IntIndex(table.timeColumn(colIndex));
  } else if (type instanceof StringColumnType || type instanceof TextColumnType) {
    return new StringIndex(table.stringColumn(colIndex));
  } else if (type instanceof IntColumnType) {
    return new IntIndex(table.intColumn(colIndex));
  } else if (type instanceof LongColumnType) {
    return new LongIndex(table.longColumn(colIndex));
  } else if (type instanceof ShortColumnType) {
    return new ShortIndex(table.shortColumn(colIndex));
  } else if (type instanceof BooleanColumnType) {
    return new ByteIndex(table.booleanColumn(colIndex));
  } else if (type instanceof DoubleColumnType) {
    return new DoubleIndex(table.doubleColumn(colIndex));
  } else if (type instanceof FloatColumnType) {
    return new FloatIndex(table.floatColumn(colIndex));
  }
  throw new IllegalArgumentException("Joining attempted on unsupported column type " + type);
}
 
Example 5
Source File: DotPlotExample.java    From tablesaw with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

    Table bush = Table.read().csv("../data/bush.csv");

    NumericColumn<?> x = bush.nCol("approval");
    CategoricalColumn<?> y = bush.stringColumn("who");

    Layout layout = Layout.builder().title("Approval ratings by agency").build();

    ScatterTrace trace = ScatterTrace.builder(x, y).mode(ScatterTrace.Mode.MARKERS).build();
    Plot.show(new Figure(layout, trace));

    // A more complex example involving two traces
    IntColumn year = bush.dateColumn("date").year();
    year.setName("year");
    bush.addColumns(year);
    bush.dropWhere(bush.intColumn("year").isIn((Number) 2001, (Number) 2002));
    Table summary = bush.summarize("approval", AggregateFunctions.mean).by("who", "year");

    Layout layout2 =
        Layout.builder()
            .title("Mean approval ratings by agency and year for 2001 and 2002")
            .build();

    Table year1 = summary.where(summary.intColumn("year").isEqualTo(2001));
    Table year2 = summary.where(summary.intColumn("year").isEqualTo(2002));
    ScatterTrace trace2 =
        ScatterTrace.builder(year1.nCol("Mean [approval]"), year1.stringColumn("who"))
            .name("2001")
            .mode(ScatterTrace.Mode.MARKERS)
            .marker(Marker.builder().symbol(Symbol.DIAMOND).color("red").size(10).build())
            .build();

    ScatterTrace trace3 =
        ScatterTrace.builder(year2.nCol("Mean [approval]"), year2.stringColumn("who"))
            .name("2002")
            .mode(ScatterTrace.Mode.MARKERS)
            .marker(Marker.builder().symbol(Symbol.STAR).size(10).color("blue").build())
            .build();

    Plot.show(new Figure(layout2, trace2, trace3));
  }
 
Example 6
Source File: GettingStarted.java    From tablesaw with Apache License 2.0 4 votes vote down vote up
private void workingWithTablesColumns() {

    // Setup code.
    Table table = Table.create();
    StringColumn column1 = StringColumn.create("col1");
    StringColumn column2 = StringColumn.create("col2");
    StringColumn column3 = StringColumn.create("col3");

    try {
      // @@ working_with_columns_examples
      List<String> columnNames = table.columnNames(); // returns all column names
      List<Column<?>> columns = table.columns(); // returns all the columns in the table

      // removing columns
      table.removeColumns("Foo"); // keep everything but "foo"
      table.retainColumns("Foo", "Bar"); // only keep foo and bar
      table.removeColumnsWithMissingValues();

      // adding columns
      table.addColumns(column1, column2, column3);
      // @@ working_with_columns_examples

      // @@ get_column_case_insensitive
      table.column("FOO");
      table.column("foo");
      table.column("foO");
      // @@ get_column_case_insensitive

      // @@ get_column
      table.column("Foo"); // returns the column named 'Foo' if it's in the table.
      // or
      table.column(0); // returns the first column
      // @@ get_column

      // @@ get_column_cast
      StringColumn sc = (StringColumn) table.column(0);
      // @@ get_column_cast

      // @@ get_typed_columns
      StringColumn strings = table.stringColumn(0);
      DateColumn dates = table.dateColumn("start date");
      DoubleColumn doubles = table.doubleColumn("doubles");
      // @@ get_typed_columns

    } catch (Exception e) {
    }
  }
 
Example 7
Source File: TableSliceGroupTest.java    From tablesaw with Apache License 2.0 4 votes vote down vote up
@Test
public void testCustomFunction() {
  Table exaggeration = table.summarize("approval", exaggerate).by("who");
  StringColumn group = exaggeration.stringColumn(0);
  assertTrue(group.contains("fox"));
}
 
Example 8
Source File: DotPlotExample.java    From tablesaw with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

    Table bush = Table.read().csv("../data/bush.csv");

    NumericColumn<?> x = bush.nCol("approval");
    CategoricalColumn<?> y = bush.stringColumn("who");

    Layout layout = Layout.builder().title("Approval ratings by agency").build();

    ScatterTrace trace = ScatterTrace.builder(x, y).mode(ScatterTrace.Mode.MARKERS).build();
    Plot.show(new Figure(layout, trace));

    // A more complex example involving two traces
    IntColumn year = bush.dateColumn("date").year();
    year.setName("year");
    bush.addColumns(year);
    bush.dropWhere(bush.intColumn("year").isIn((Number) 2001, (Number) 2002));
    Table summary = bush.summarize("approval", AggregateFunctions.mean).by("who", "year");

    Layout layout2 =
        Layout.builder()
            .title("Mean approval ratings by agency and year for 2001 and 2002")
            .build();

    Table year1 = summary.where(summary.intColumn("year").isEqualTo(2001));
    Table year2 = summary.where(summary.intColumn("year").isEqualTo(2002));
    ScatterTrace trace2 =
        ScatterTrace.builder(year1.nCol("Mean [approval]"), year1.stringColumn("who"))
            .name("2001")
            .mode(ScatterTrace.Mode.MARKERS)
            .marker(Marker.builder().symbol(Symbol.DIAMOND).color("red").size(10).build())
            .build();

    ScatterTrace trace3 =
        ScatterTrace.builder(year2.nCol("Mean [approval]"), year2.stringColumn("who"))
            .name("2002")
            .mode(ScatterTrace.Mode.MARKERS)
            .marker(Marker.builder().symbol(Symbol.STAR).size(10).color("blue").build())
            .build();

    Plot.show(new Figure(layout2, trace2, trace3));
  }
 
Example 9
Source File: GettingStarted.java    From tablesaw with Apache License 2.0 4 votes vote down vote up
private void workingWithTablesColumns() {

    // Setup code.
    Table table = Table.create();
    StringColumn column1 = StringColumn.create("col1");
    StringColumn column2 = StringColumn.create("col2");
    StringColumn column3 = StringColumn.create("col3");

    try {
      // @@ working_with_columns_examples
      List<String> columnNames = table.columnNames(); // returns all column names
      List<Column<?>> columns = table.columns(); // returns all the columns in the table

      // removing columns
      table.removeColumns("Foo"); // keep everything but "foo"
      table.retainColumns("Foo", "Bar"); // only keep foo and bar
      table.removeColumnsWithMissingValues();

      // adding columns
      table.addColumns(column1, column2, column3);
      // @@ working_with_columns_examples

      // @@ get_column_case_insensitive
      table.column("FOO");
      table.column("foo");
      table.column("foO");
      // @@ get_column_case_insensitive

      // @@ get_column
      table.column("Foo"); // returns the column named 'Foo' if it's in the table.
      // or
      table.column(0); // returns the first column
      // @@ get_column

      // @@ get_column_cast
      StringColumn sc = (StringColumn) table.column(0);
      // @@ get_column_cast

      // @@ get_typed_columns
      StringColumn strings = table.stringColumn(0);
      DateColumn dates = table.dateColumn("start date");
      DoubleColumn doubles = table.doubleColumn("doubles");
      // @@ get_typed_columns

    } catch (Exception e) {
    }
  }
 
Example 10
Source File: TableSliceGroupTest.java    From tablesaw with Apache License 2.0 4 votes vote down vote up
@Test
public void testCustomFunction() {
  Table exaggeration = table.summarize("approval", exaggerate).by("who");
  StringColumn group = exaggeration.stringColumn(0);
  assertTrue(group.contains("fox"));
}