Search in sources :

Example 1 with IntColumn

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

the class Summarizer method having.

public Table having(Function<Table, Selection> selection) {
    Preconditions.checkState(groupColumnNames.length > 0, "Cannot perform having() on summary that has not been grouped first");
    if (groupColumnNames[0].equals(GROUP_COL_TEMP_NAME)) {
        IntColumn groupColumn = temp.intColumn(GROUP_COL_TEMP_NAME);
        TableSliceGroup group = StandardTableSliceGroup.create(temp, groupColumn);
        return summarizeForHaving(group, selection);
    } else {
        TableSliceGroup group = StandardTableSliceGroup.create(temp, groupColumnNames);
        return summarizeForHaving(group, selection);
    }
}
Also used : StandardTableSliceGroup(tech.tablesaw.table.StandardTableSliceGroup) TableSliceGroup(tech.tablesaw.table.TableSliceGroup) IntColumn(tech.tablesaw.api.IntColumn)

Example 2 with IntColumn

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

the class Summarizer method assignToGroupsByStep.

private IntColumn assignToGroupsByStep(int step) {
    IntColumn groupColumn = IntColumn.create(GROUP_COL_TEMP_NAME, temp.rowCount());
    temp.addColumns(groupColumn);
    int groupId = 1;
    int withinGroupCount = 0;
    Row row = new Row(temp);
    while (row.hasNext()) {
        row.next();
        if (withinGroupCount < step) {
            withinGroupCount++;
            groupColumn.set(row.getRowNumber(), groupId);
        } else {
            groupId++;
            groupColumn.set(row.getRowNumber(), groupId);
            withinGroupCount = 1;
        }
    }
    int lastGroupSize = temp.where(numberColumn(GROUP_COL_TEMP_NAME).isEqualTo(groupId)).rowCount();
    if (lastGroupSize < step) {
        temp = temp.dropWhere(numberColumn(GROUP_COL_TEMP_NAME).isEqualTo(groupId));
    }
    temp.addColumns(IntColumn.indexColumn("index", temp.rowCount(), 1));
    return groupColumn;
}
Also used : Row(tech.tablesaw.api.Row) IntColumn(tech.tablesaw.api.IntColumn)

Example 3 with IntColumn

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

the class Summarizer method groupBy.

public Summarizer groupBy(int step) {
    IntColumn groupColumn = assignToGroupsByStep(step);
    if (tableDoesNotContain(groupColumn.name(), temp)) {
        temp.addColumns(groupColumn);
    }
    groupColumnNames = new String[] { GROUP_COL_TEMP_NAME };
    return this;
}
Also used : IntColumn(tech.tablesaw.api.IntColumn)

Example 4 with IntColumn

use of tech.tablesaw.api.IntColumn 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 5 with IntColumn

use of tech.tablesaw.api.IntColumn 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

IntColumn (tech.tablesaw.api.IntColumn)22 Table (tech.tablesaw.api.Table)7 StringColumn (tech.tablesaw.api.StringColumn)4 Map (java.util.Map)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 DoubleColumn (tech.tablesaw.api.DoubleColumn)2 TreeBasedTable (com.google.common.collect.TreeBasedTable)1 Byte2IntMap (it.unimi.dsi.fastutil.bytes.Byte2IntMap)1 Byte2IntOpenHashMap (it.unimi.dsi.fastutil.bytes.Byte2IntOpenHashMap)1 Byte2ObjectMap (it.unimi.dsi.fastutil.bytes.Byte2ObjectMap)1 Byte2ObjectOpenHashMap (it.unimi.dsi.fastutil.bytes.Byte2ObjectOpenHashMap)1 Int2IntMap (it.unimi.dsi.fastutil.ints.Int2IntMap)1 Int2IntOpenHashMap (it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap)1 Int2ObjectMap (it.unimi.dsi.fastutil.ints.Int2ObjectMap)1 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)1 Object2ByteOpenHashMap (it.unimi.dsi.fastutil.objects.Object2ByteOpenHashMap)1 Object2IntOpenHashMap (it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap)1 Object2ShortOpenHashMap (it.unimi.dsi.fastutil.objects.Object2ShortOpenHashMap)1 Short2IntMap (it.unimi.dsi.fastutil.shorts.Short2IntMap)1 Short2IntOpenHashMap (it.unimi.dsi.fastutil.shorts.Short2IntOpenHashMap)1