Search in sources :

Example 21 with StringColumn

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

the class TableSliceGroup method aggregate.

/**
 * 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 (function.returnType().equals(ColumnType.DOUBLE)) {
                    Number number = (Number) result;
                    resultColumn.append(number.doubleValue());
                } else {
                    resultColumn.append(result);
                }
            }
            groupTable.addColumns(resultColumn);
            firstFunction = false;
        }
    }
    return splitGroupingColumn(groupTable);
}
Also used : StringColumn(tech.tablesaw.api.StringColumn) Table(tech.tablesaw.api.Table) ColumnType(tech.tablesaw.api.ColumnType) StringColumn(tech.tablesaw.api.StringColumn) Column(tech.tablesaw.columns.Column) AggregateFunction(tech.tablesaw.aggregate.AggregateFunction) Collection(java.util.Collection) Map(java.util.Map)

Example 22 with StringColumn

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

the class DateMapFunctions method yearMonth.

/**
 * Returns a StringColumn with the year and month from this column concatenated into a String that
 * will sort lexicographically in temporal order.
 *
 * <p>This simplifies the production of plots and tables that aggregate values into standard
 * temporal units (e.g., you want monthly data but your source data is more than a year long and
 * you don't want months from different years aggregated together).
 */
default StringColumn yearMonth() {
    StringColumn newColumn = StringColumn.create(this.name() + " year & month");
    for (int r = 0; r < this.size(); r++) {
        int c1 = this.getIntInternal(r);
        if (DateColumn.valueIsMissing(c1)) {
            newColumn.appendMissing();
        } else {
            String ym = String.valueOf(PackedLocalDate.getYear(c1));
            ym = ym + "-" + Strings.padStart(String.valueOf(PackedLocalDate.getMonthValue(c1)), 2, '0');
            newColumn.append(ym);
        }
    }
    return newColumn;
}
Also used : StringColumn(tech.tablesaw.api.StringColumn)

Example 23 with StringColumn

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

the class DateMapFunctions method yearQuarter.

/**
 * Returns a StringColumn with the year and quarter from this column concatenated into a String
 * that will sort lexicographically in temporal order.
 *
 * <p>This simplifies the production of plots and tables that aggregate values into standard
 * temporal units (e.g., you want monthly data but your source data is more than a year long and
 * you don't want months from different years aggregated together).
 */
default StringColumn yearQuarter() {
    StringColumn newColumn = StringColumn.create(this.name() + " year & quarter");
    for (int r = 0; r < this.size(); r++) {
        int c1 = this.getIntInternal(r);
        if (DateColumn.valueIsMissing(c1)) {
            newColumn.appendMissing();
        } else {
            String yq = String.valueOf(PackedLocalDate.getYear(c1));
            yq = yq + "-" + Strings.padStart(String.valueOf(PackedLocalDate.getQuarter(c1)), 2, '0');
            newColumn.append(yq);
        }
    }
    return newColumn;
}
Also used : StringColumn(tech.tablesaw.api.StringColumn)

Example 24 with StringColumn

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

the class DateTimeMapFunctions method yearQuarter.

/**
 * Returns a StringColumn with the year and quarter from this column concatenated into a String
 * that will sort lexicographically in temporal order.
 *
 * <p>This simplifies the production of plots and tables that aggregate values into standard
 * temporal units (e.g., you want monthly data but your source data is more than a year long and
 * you don't want months from different years aggregated together).
 */
default StringColumn yearQuarter() {
    StringColumn newColumn = StringColumn.create(this.name() + " year & quarter");
    for (int r = 0; r < this.size(); r++) {
        long c1 = this.getLongInternal(r);
        if (DateTimeColumn.valueIsMissing(c1)) {
            newColumn.append(StringColumnType.missingValueIndicator());
        } else {
            String yq = getYear(c1) + "-" + getQuarter(c1);
            newColumn.append(yq);
        }
    }
    return newColumn;
}
Also used : StringColumn(tech.tablesaw.api.StringColumn)

Example 25 with StringColumn

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

the class DateTimeMapFunctions method hourMinute.

/**
 * Returns a StringColumn with the year and week-of-year derived from this column concatenated
 * into a String that will sort lexicographically in temporal order.
 *
 * <p>This simplifies the production of plots and tables that aggregate values into standard
 * temporal units (e.g., you want monthly data but your source data is more than a year long and
 * you don't want months from different years aggregated together).
 */
default StringColumn hourMinute() {
    StringColumn newColumn = StringColumn.create(this.name() + " hour & minute");
    for (int r = 0; r < this.size(); r++) {
        long c1 = this.getLongInternal(r);
        if (DateTimeColumn.valueIsMissing(c1)) {
            newColumn.append(StringColumnType.missingValueIndicator());
        } else {
            String hm = Strings.padStart(String.valueOf(getHour(c1)), 2, '0');
            hm = hm + ":" + Strings.padStart(String.valueOf(getMinute(c1)), 2, '0');
            newColumn.append(hm);
        }
    }
    return newColumn;
}
Also used : StringColumn(tech.tablesaw.api.StringColumn)

Aggregations

StringColumn (tech.tablesaw.api.StringColumn)39 Table (tech.tablesaw.api.Table)10 DoubleColumn (tech.tablesaw.api.DoubleColumn)5 Splitter (com.google.common.base.Splitter)4 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 IntColumn (tech.tablesaw.api.IntColumn)4 TreeBasedTable (com.google.common.collect.TreeBasedTable)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 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