Search in sources :

Example 1 with StringColumn

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

the class CrossTab method tablePercents.

private static Table tablePercents(Table xTabCounts) {
    Table pctTable = Table.create("Crosstab Table Proportions: ");
    StringColumn labels = StringColumn.create(LABEL_COLUMN_NAME);
    pctTable.addColumns(labels);
    double grandTotal = xTabCounts.numberColumn(xTabCounts.columnCount() - 1).getDouble(xTabCounts.rowCount() - 1);
    for (int i = 0; i < xTabCounts.rowCount(); i++) {
        labels.append(xTabCounts.column(0).getString(i));
    }
    // create the new cols
    DoubleColumn[] newColumns = new DoubleColumn[xTabCounts.columnCount() - 1];
    for (int i = 1; i < xTabCounts.columnCount(); i++) {
        Column<?> column = xTabCounts.column(i);
        newColumns[i - 1] = DoubleColumn.create(column.name());
    }
    for (int i = 0; i < xTabCounts.rowCount(); i++) {
        for (int c = 0; c < newColumns.length; c++) {
            if (grandTotal == 0) {
                newColumns[c].append(Double.NaN);
            } else {
                newColumns[c].append(xTabCounts.numberColumn(c + 1).getDouble(i) / grandTotal);
            }
        }
    }
    pctTable.addColumns(newColumns);
    return pctTable;
}
Also used : StringColumn(tech.tablesaw.api.StringColumn) Table(tech.tablesaw.api.Table) TreeBasedTable(com.google.common.collect.TreeBasedTable) DoubleColumn(tech.tablesaw.api.DoubleColumn)

Example 2 with StringColumn

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

the class CrossTab method columnPercents.

private static Table columnPercents(Table xTabCounts) {
    Table pctTable = Table.create("Crosstab Column Proportions: ");
    StringColumn labels = StringColumn.create(LABEL_COLUMN_NAME);
    pctTable.addColumns(labels);
    // setup the labels
    for (int i = 0; i < xTabCounts.rowCount(); i++) {
        labels.append(xTabCounts.column(0).getString(i));
    }
    // create the new cols
    DoubleColumn[] newColumns = new DoubleColumn[xTabCounts.columnCount() - 1];
    for (int i = 1; i < xTabCounts.columnCount(); i++) {
        Column<?> column = xTabCounts.column(i);
        newColumns[i - 1] = DoubleColumn.create(column.name());
    }
    // get the column totals
    double[] columnTotals = new double[newColumns.length];
    int totalRow = xTabCounts.rowCount() - 1;
    for (int i = 1; i < xTabCounts.columnCount(); i++) {
        columnTotals[i - 1] = xTabCounts.numberColumn(i).getDouble(totalRow);
    }
    // calculate the column pcts and update the new table
    for (int i = 0; i < xTabCounts.rowCount(); i++) {
        for (int c = 0; c < newColumns.length; c++) {
            if (columnTotals[c] == 0) {
                newColumns[c].append(Double.NaN);
            } else {
                newColumns[c].append(xTabCounts.numberColumn(c + 1).getDouble(i) / columnTotals[c]);
            }
        }
    }
    pctTable.addColumns(newColumns);
    return pctTable;
}
Also used : StringColumn(tech.tablesaw.api.StringColumn) Table(tech.tablesaw.api.Table) TreeBasedTable(com.google.common.collect.TreeBasedTable) DoubleColumn(tech.tablesaw.api.DoubleColumn)

Example 3 with StringColumn

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

the class DateMapFunctions method yearWeek.

/**
 * 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 yearWeek() {
    StringColumn newColumn = StringColumn.create(this.name() + " year & week");
    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.getWeekOfYear(c1)), 2, '0');
            newColumn.append(ym);
        }
    }
    return newColumn;
}
Also used : StringColumn(tech.tablesaw.api.StringColumn)

Example 4 with StringColumn

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

the class DateMapFunctions method yearDay.

/**
 * Returns a StringColumn with the year and day-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 yearDay() {
    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.getDayOfYear(c1)), 3, '0');
            newColumn.append(ym);
        }
    }
    return newColumn;
}
Also used : StringColumn(tech.tablesaw.api.StringColumn)

Example 5 with StringColumn

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

the class DateTimeMapFunctions 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++) {
        long c1 = this.getLongInternal(r);
        if (DateTimeColumn.valueIsMissing(c1)) {
            newColumn.append(StringColumnType.missingValueIndicator());
        } else {
            String ym = String.valueOf(getYear(c1));
            ym = ym + "-" + Strings.padStart(String.valueOf(getMonthValue(c1)), 2, '0');
            newColumn.append(ym);
        }
    }
    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