Search in sources :

Example 26 with StringColumn

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

the class CrossTab method rowPercents.

private static Table rowPercents(Table xTabCounts) {
    Table pctTable = Table.create("Crosstab Row Proportions: ");
    StringColumn labels = StringColumn.create(LABEL_COLUMN_NAME);
    pctTable.addColumns(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());
    }
    for (int i = 0; i < xTabCounts.rowCount(); i++) {
        double rowTotal = xTabCounts.numberColumn(xTabCounts.columnCount() - 1).getDouble(i);
        for (int c = 0; c < newColumns.length; c++) {
            if (rowTotal == 0) {
                newColumns[c].append(Double.NaN);
            } else {
                newColumns[c].append(xTabCounts.numberColumn(c + 1).getDouble(i) / rowTotal);
            }
        }
    }
    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 27 with StringColumn

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

the class Relation method structure.

public Table structure() {
    Table t = Table.create("Structure of " + name());
    IntColumn index = IntColumn.indexColumn("Index", columnCount(), 0);
    StringColumn columnName = StringColumn.create("Column Name", columnCount());
    StringColumn columnType = StringColumn.create("Column Type", columnCount());
    t.addColumns(index);
    t.addColumns(columnName);
    t.addColumns(columnType);
    for (int i = 0; i < columnCount(); i++) {
        Column<?> column = this.columns().get(i);
        columnType.set(i, column.type().name());
        columnName.set(i, columnNames().get(i));
    }
    return t;
}
Also used : StringColumn(tech.tablesaw.api.StringColumn) Table(tech.tablesaw.api.Table) IntColumn(tech.tablesaw.api.IntColumn)

Example 28 with StringColumn

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

the class TimeMapFunctions method hourMinute.

/**
 * Returns a StringColumn with the hour and minute-of-hour 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
 */
default StringColumn hourMinute() {
    StringColumn newColumn = StringColumn.create(this.name() + " hour & minute");
    for (int r = 0; r < this.size(); r++) {
        int c1 = this.getIntInternal(r);
        if (TimeColumn.valueIsMissing(c1)) {
            newColumn.append(StringColumnType.missingValueIndicator());
        } else {
            String hm = Strings.padStart(String.valueOf(PackedLocalTime.getHour(c1)), 2, '0');
            hm = hm + "-" + Strings.padStart(String.valueOf(PackedLocalTime.getMinute(c1)), 2, '0');
            newColumn.append(hm);
        }
    }
    return newColumn;
}
Also used : StringColumn(tech.tablesaw.api.StringColumn)

Example 29 with StringColumn

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

the class ShortDictionaryMap method countByCategory.

/**
 */
@Override
public Table countByCategory(String columnName) {
    Table t = Table.create("Column: " + columnName);
    StringColumn categories = StringColumn.create("Category");
    IntColumn counts = IntColumn.create("Count");
    // Now uses the keyToCount map
    for (Map.Entry<Short, Integer> entry : keyToCount.short2IntEntrySet()) {
        categories.append(getValueForKey(entry.getKey()));
        counts.append(entry.getValue());
    }
    t.addColumns(categories);
    t.addColumns(counts);
    return t;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StringColumn(tech.tablesaw.api.StringColumn) Table(tech.tablesaw.api.Table) Short2IntOpenHashMap(it.unimi.dsi.fastutil.shorts.Short2IntOpenHashMap) Map(java.util.Map) Short2IntMap(it.unimi.dsi.fastutil.shorts.Short2IntMap) Object2ShortOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ShortOpenHashMap) Short2ObjectOpenHashMap(it.unimi.dsi.fastutil.shorts.Short2ObjectOpenHashMap) Short2ObjectMap(it.unimi.dsi.fastutil.shorts.Short2ObjectMap) IntColumn(tech.tablesaw.api.IntColumn)

Example 30 with StringColumn

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

the class StringMapFunctions method capitalize.

/**
 * Capitalizes each String changing the first character of each to title case as per {@link
 * Character#toTitleCase(int)}, as if in a sentence. No other characters are changed.
 *
 * <pre>
 * capitalize(null)  = null
 * capitalize("")    = ""
 * capitalize("cat") = "Cat"
 * capitalize("cAt") = "CAt"
 * capitalize("'cat'") = "'cat'"
 * </pre>
 */
default StringColumn capitalize() {
    StringColumn newColumn = StringColumn.create(name() + "[titleCase]");
    for (int r = 0; r < size(); r++) {
        String value = getString(r);
        newColumn.append(StringUtils.capitalize(value));
    }
    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