Search in sources :

Example 6 with StringColumn

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

the class DateTimeMapFunctions 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++) {
        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(getWeekOfYear(c1)), 2, '0');
            newColumn.append(ym);
        }
    }
    return newColumn;
}
Also used : StringColumn(tech.tablesaw.api.StringColumn)

Example 7 with StringColumn

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

the class DateTimeMapFunctions 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++) {
        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(getDayOfYear(c1)), 3, '0');
            newColumn.append(ym);
        }
    }
    return newColumn;
}
Also used : StringColumn(tech.tablesaw.api.StringColumn)

Example 8 with StringColumn

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

the class ByteDictionaryMap 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<Byte, Integer> entry : keyToCount.byte2IntEntrySet()) {
        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) Byte2ObjectOpenHashMap(it.unimi.dsi.fastutil.bytes.Byte2ObjectOpenHashMap) Map(java.util.Map) Byte2ObjectMap(it.unimi.dsi.fastutil.bytes.Byte2ObjectMap) Byte2IntOpenHashMap(it.unimi.dsi.fastutil.bytes.Byte2IntOpenHashMap) Byte2IntMap(it.unimi.dsi.fastutil.bytes.Byte2IntMap) Object2ByteOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ByteOpenHashMap) IntColumn(tech.tablesaw.api.IntColumn)

Example 9 with StringColumn

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

the class IntDictionaryMap 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<Integer, Integer> entry : keyToCount.int2IntEntrySet()) {
        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) Int2IntMap(it.unimi.dsi.fastutil.ints.Int2IntMap) Map(java.util.Map) Object2IntOpenHashMap(it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) Int2IntOpenHashMap(it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap) Int2ObjectMap(it.unimi.dsi.fastutil.ints.Int2ObjectMap) IntColumn(tech.tablesaw.api.IntColumn)

Example 10 with StringColumn

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

the class StringMapFunctions method repeat.

/**
 * Repeats each the column's values elementwise, concatinating the results into a new StringColumn
 *
 * @param times The number of repeat desired
 *     <pre>
 *  repeat("", 2)   = ""
 *  repeat("cat", 3) = "catcatcat"
 * </pre>
 *
 * @return the new StringColumn
 */
default StringColumn repeat(int times) {
    StringColumn newColumn = StringColumn.create(String.format("%s [rep %d]", name(), times));
    for (int r = 0; r < size(); r++) {
        String value = getString(r);
        newColumn.append(StringUtils.repeat(value, times));
    }
    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