Search in sources :

Example 16 with Table

use of tech.tablesaw.api.Table 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 17 with Table

use of tech.tablesaw.api.Table 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 18 with Table

use of tech.tablesaw.api.Table 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 19 with Table

use of tech.tablesaw.api.Table 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 20 with Table

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

the class Stats method asTable.

public Table asTable() {
    Table t = Table.create(name);
    StringColumn measure = StringColumn.create("Measure");
    DoubleColumn value = DoubleColumn.create("Value");
    t.addColumns(measure);
    t.addColumns(value);
    measure.append("Count");
    value.append(n);
    measure.append("sum");
    value.append(sum());
    measure.append("Mean");
    value.append(mean());
    measure.append("Min");
    value.append(min());
    measure.append("Max");
    value.append(max());
    measure.append("Range");
    value.append(range());
    measure.append("Variance");
    value.append(variance());
    measure.append("Std. Dev");
    value.append(standardDeviation());
    return t;
}
Also used : StringColumn(tech.tablesaw.api.StringColumn) Table(tech.tablesaw.api.Table) DoubleColumn(tech.tablesaw.api.DoubleColumn)

Aggregations

Table (tech.tablesaw.api.Table)42 StringColumn (tech.tablesaw.api.StringColumn)10 ArrayList (java.util.ArrayList)9 DoubleColumn (tech.tablesaw.api.DoubleColumn)8 IntColumn (tech.tablesaw.api.IntColumn)8 ColumnType (tech.tablesaw.api.ColumnType)7 Column (tech.tablesaw.columns.Column)7 TreeBasedTable (com.google.common.collect.TreeBasedTable)5 Map (java.util.Map)5 List (java.util.List)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 IExpr (org.matheclipse.core.interfaces.IExpr)3 ExprColumn (tech.tablesaw.api.ExprColumn)3 Row (tech.tablesaw.api.Row)3 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 IAST (org.matheclipse.core.interfaces.IAST)2 Strings (com.google.common.base.Strings)1 Lists (com.google.common.collect.Lists)1