Java Code Examples for tech.tablesaw.columns.Column#append()

The following examples show how to use tech.tablesaw.columns.Column#append() . 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: Table.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
private Table transpose(
    Table transposed,
    ColumnType resultColumnType,
    IntFunction<String> columnNameExtractor,
    int startingColumn) {

  for (int row = 0; row < this.rowCount(); row++) {
    String columnName = columnNameExtractor.apply(row);
    Column column = resultColumnType.create(columnName);

    for (int col = startingColumn; col < this.columnCount(); col++) {
      column.append(this.column(col), row);
    }
    transposed.addColumns(column);
  }
  return transposed;
}
 
Example 2
Source File: Table.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
private Table transpose(
    Table transposed,
    ColumnType resultColumnType,
    IntFunction<String> columnNameExtractor,
    int startingColumn) {

  for (int row = 0; row < this.rowCount(); row++) {
    String columnName = columnNameExtractor.apply(row);
    Column column = resultColumnType.create(columnName);

    for (int col = startingColumn; col < this.columnCount(); col++) {
      column.append(this.column(col), row);
    }
    transposed.addColumns(column);
  }
  return transposed;
}
 
Example 3
Source File: Summarizer.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the result of applying to the functions to all the values in the appropriate column
 * TODO add a test that uses a non numeric return type with apply
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public Table apply() {

  if (groupColumnNames.length > 0) {
    TableSliceGroup group = StandardTableSliceGroup.create(temp, groupColumnNames);
    return summarize(group);
  } else {
    List<Table> results = new ArrayList<>();
    ArrayListMultimap<String, AggregateFunction<?, ?>> reductionMultimap =
        getAggregateFunctionMultimap();

    for (String name : reductionMultimap.keys()) {
      List<AggregateFunction<?, ?>> reductions = reductionMultimap.get(name);
      Table table = TableSliceGroup.summaryTableName(temp);
      for (AggregateFunction function : reductions) {
        Column column = temp.column(name);
        Object result = function.summarize(column);
        ColumnType type = function.returnType();
        Column newColumn =
            type.create(TableSliceGroup.aggregateColumnName(name, function.functionName()));
        if (result instanceof Number) {
          Number number = (Number) result;
          newColumn.append(number.doubleValue());
        } else {
          newColumn.append(result);
        }
        table.addColumns(newColumn);
      }
      results.add(table);
    }
    return (combineTables(results));
  }
}
 
Example 4
Source File: Table.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"rawtypes", "unchecked"})
public Table append(Table tableToAppend) {
  for (final Column column : columnList) {
    final Column columnToAppend = tableToAppend.column(column.name());
    column.append(columnToAppend);
  }
  return this;
}
 
Example 5
Source File: TableSliceGroup.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
/**
 * Applies the given aggregations to the given columns. The apply and combine steps of a
 * split-apply-combine.
 *
 * @param functions map from column name to aggregation to apply on that function
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public Table aggregate(ListMultimap<String, AggregateFunction<?, ?>> functions) {
  Table groupTable = summaryTableName(sourceTable);
  StringColumn groupColumn = StringColumn.create("Group");
  groupTable.addColumns(groupColumn);
  boolean firstFunction = true;
  for (Map.Entry<String, Collection<AggregateFunction<?, ?>>> entry :
      functions.asMap().entrySet()) {
    String columnName = entry.getKey();
    for (AggregateFunction function : entry.getValue()) {
      String colName = aggregateColumnName(columnName, function.functionName());
      ColumnType type = function.returnType();
      Column resultColumn = type.create(colName);
      for (TableSlice subTable : getSlices()) {
        Object result = function.summarize(subTable.column(columnName));
        if (firstFunction) {
          groupColumn.append(subTable.name());
        }
        if (result instanceof Number) {
          Number number = (Number) result;
          resultColumn.append(number.doubleValue());
        } else {
          resultColumn.append(result);
        }
      }
      groupTable.addColumns(resultColumn);
      firstFunction = false;
    }
  }
  return splitGroupingColumn(groupTable);
}
 
Example 6
Source File: Summarizer.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the result of applying to the functions to all the values in the appropriate column
 * TODO add a test that uses a non numeric return type with apply
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public Table apply() {

  if (groupColumnNames.length > 0) {
    TableSliceGroup group = StandardTableSliceGroup.create(temp, groupColumnNames);
    return summarize(group);
  } else {
    List<Table> results = new ArrayList<>();
    ArrayListMultimap<String, AggregateFunction<?, ?>> reductionMultimap =
        getAggregateFunctionMultimap();

    for (String name : reductionMultimap.keys()) {
      List<AggregateFunction<?, ?>> reductions = reductionMultimap.get(name);
      Table table = TableSliceGroup.summaryTableName(temp);
      for (AggregateFunction function : reductions) {
        Column column = temp.column(name);
        Object result = function.summarize(column);
        ColumnType type = function.returnType();
        Column newColumn =
            type.create(TableSliceGroup.aggregateColumnName(name, function.functionName()));
        if (result instanceof Number) {
          Number number = (Number) result;
          newColumn.append(number.doubleValue());
        } else {
          newColumn.append(result);
        }
        table.addColumns(newColumn);
      }
      results.add(table);
    }
    return (combineTables(results));
  }
}
 
Example 7
Source File: Table.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"rawtypes", "unchecked"})
public Table append(Table tableToAppend) {
  for (final Column column : columnList) {
    final Column columnToAppend = tableToAppend.column(column.name());
    column.append(columnToAppend);
  }
  return this;
}
 
Example 8
Source File: TableSliceGroup.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
/**
 * Applies the given aggregations to the given columns. The apply and combine steps of a
 * split-apply-combine.
 *
 * @param functions map from column name to aggregation to apply on that function
 */
@SuppressWarnings({"unchecked", "rawtypes"})
public Table aggregate(ListMultimap<String, AggregateFunction<?, ?>> functions) {
  Table groupTable = summaryTableName(sourceTable);
  StringColumn groupColumn = StringColumn.create("Group");
  groupTable.addColumns(groupColumn);
  boolean firstFunction = true;
  for (Map.Entry<String, Collection<AggregateFunction<?, ?>>> entry :
      functions.asMap().entrySet()) {
    String columnName = entry.getKey();
    for (AggregateFunction function : entry.getValue()) {
      String colName = aggregateColumnName(columnName, function.functionName());
      ColumnType type = function.returnType();
      Column resultColumn = type.create(colName);
      for (TableSlice subTable : getSlices()) {
        Object result = function.summarize(subTable.column(columnName));
        if (firstFunction) {
          groupColumn.append(subTable.name());
        }
        if (result instanceof Number) {
          Number number = (Number) result;
          resultColumn.append(number.doubleValue());
        } else {
          resultColumn.append(result);
        }
      }
      groupTable.addColumns(resultColumn);
      firstFunction = false;
    }
  }
  return splitGroupingColumn(groupTable);
}