Search in sources :

Example 11 with Table

use of tech.tablesaw.api.Table in project symja_android_library by axkr.

the class PivotTable method pivot.

public static Table pivot(Table table, CategoricalColumn<?> column1, CategoricalColumn<?> column2, NumericColumn<?> values, AggregateFunction<?, ?> aggregateFunction) {
    TableSliceGroup tsg = table.splitOn(column1);
    Table pivotTable = Table.create("Pivot: " + column1.name() + " x " + column2.name());
    pivotTable.addColumns(column1.type().create(column1.name()));
    List<String> valueColumnNames = getValueColumnNames(table, column2);
    for (String colName : valueColumnNames) {
        pivotTable.addColumns(DoubleColumn.create(colName));
    }
    int valueIndex = table.columnIndex(column2);
    int keyIndex = table.columnIndex(column1);
    String key;
    for (TableSlice slice : tsg.getSlices()) {
        key = String.valueOf(slice.get(0, keyIndex));
        pivotTable.column(0).appendCell(key);
        Map<String, Double> valueMap = getValueMap(column1, column2, values, valueIndex, slice, aggregateFunction);
        for (String columnName : valueColumnNames) {
            Double aDouble = valueMap.get(columnName);
            NumericColumn<?> pivotValueColumn = pivotTable.numberColumn(columnName);
            if (aDouble == null) {
                pivotValueColumn.appendMissing();
            } else {
                pivotValueColumn.appendObj(aDouble);
            }
        }
    }
    return pivotTable;
}
Also used : Table(tech.tablesaw.api.Table) TableSliceGroup(tech.tablesaw.table.TableSliceGroup) TableSlice(tech.tablesaw.table.TableSlice)

Example 12 with Table

use of tech.tablesaw.api.Table in project symja_android_library by axkr.

the class Summarizer method by.

/**
 * Returns a summary of the records grouped into subsets of the same size, in the order they
 * appear
 *
 * <p>All groups have the same number of records. If the final group has fewer than step records
 * it is dropped.
 *
 * @param step the number or records to include in each group
 */
public Table by(int step) {
    IntColumn groupColumn = assignToGroupsByStep(step);
    Table t = getSummaryTable(groupColumn);
    t.column(GROUP_COL_TEMP_NAME).setName("Group");
    return t;
}
Also used : Table(tech.tablesaw.api.Table) IntColumn(tech.tablesaw.api.IntColumn)

Example 13 with Table

use of tech.tablesaw.api.Table in project symja_android_library by axkr.

the class Summarizer method summarizeForHaving.

/**
 * Associates the columns to be summarized with the functions that match their type. All valid
 * combinations are used
 *
 * @param group A table slice group
 * @param selectionFunction Function that provides the filter for the having clause
 * @return A table containing a row of summarized data for each group in the table slice group
 */
private Table summarizeForHaving(TableSliceGroup group, Function<Table, Selection> selectionFunction) {
    List<Table> results = new ArrayList<>();
    ArrayListMultimap<String, AggregateFunction<?, ?>> reductionMultimap = getAggregateFunctionMultimap();
    for (String name : reductionMultimap.keys()) {
        List<AggregateFunction<?, ?>> reductions = reductionMultimap.get(name);
        Table groupTable = group.aggregate(name, reductions.toArray(new AggregateFunction<?, ?>[0]));
        groupTable = groupTable.where(selectionFunction);
        if (!groupTable.isEmpty()) {
            results.add(groupTable);
        }
    }
    return combineTables(results);
}
Also used : Table(tech.tablesaw.api.Table) ArrayList(java.util.ArrayList)

Example 14 with Table

use of tech.tablesaw.api.Table in project symja_android_library by axkr.

the class AnalyticQuery method executeInPlace.

/**
 * Executes the query and adds all the calculated columns directly to the source table.
 *
 * @throws IllegalArgumentException if any of the calculated columns have the same name as one of
 *     the columns in the FROM table.
 */
public void executeInPlace() {
    Table result = execute();
    table.concat(result);
}
Also used : Table(tech.tablesaw.api.Table)

Example 15 with Table

use of tech.tablesaw.api.Table in project symja_android_library by axkr.

the class CrossTab method percents.

public static Table percents(Table table, String column1) {
    Table countTable = counts(table, column1);
    Table percentTable = Table.create(countTable.name());
    percentTable.addColumns(countTable.column(0).copy());
    IntColumn countsColumn = countTable.intColumn("Count");
    DoubleColumn pctsColumn = DoubleColumn.create("Percents");
    double sum = countsColumn.sum();
    for (int i = 0; i < countsColumn.size(); i++) {
        pctsColumn.append(countsColumn.getDouble(i) / sum);
    }
    percentTable.addColumns(pctsColumn);
    return percentTable;
}
Also used : Table(tech.tablesaw.api.Table) TreeBasedTable(com.google.common.collect.TreeBasedTable) DoubleColumn(tech.tablesaw.api.DoubleColumn) IntColumn(tech.tablesaw.api.IntColumn)

Aggregations

Table (tech.tablesaw.api.Table)42 StringColumn (tech.tablesaw.api.StringColumn)10 ArrayList (java.util.ArrayList)9 DoubleColumn (tech.tablesaw.api.DoubleColumn)8 IntColumn (tech.tablesaw.api.IntColumn)8 ColumnType (tech.tablesaw.api.ColumnType)7 Column (tech.tablesaw.columns.Column)7 TreeBasedTable (com.google.common.collect.TreeBasedTable)5 Map (java.util.Map)5 List (java.util.List)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 IExpr (org.matheclipse.core.interfaces.IExpr)3 ExprColumn (tech.tablesaw.api.ExprColumn)3 Row (tech.tablesaw.api.Row)3 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 IAST (org.matheclipse.core.interfaces.IAST)2 Strings (com.google.common.base.Strings)1 Lists (com.google.common.collect.Lists)1