Search in sources :

Example 1 with BooleanColumn

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

the class BooleanMapUtils method andNot.

/**
 * Returns a column made by combining the receiver and each of the arguments using the operation:
 * A andNot V. For example, the value of a cell in the result column would be true if the
 * corresponding value in A is true and the corresponding value in B is false
 */
default BooleanColumn andNot(BooleanColumn... columns) {
    StringBuilder name = new StringBuilder(name()).append(" and not: ");
    Selection selection = asSelection();
    for (BooleanColumn column : columns) {
        if (!column.name().equals(columns[0].name())) {
            name.append(", ");
        }
        name.append(column.name());
        selection.andNot(column.asSelection());
    }
    return BooleanColumn.create(name.toString(), selection, size());
}
Also used : Selection(tech.tablesaw.selection.Selection) BooleanColumn(tech.tablesaw.api.BooleanColumn)

Example 2 with BooleanColumn

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

the class ByteDictionaryMap method getDummies.

/**
 * Returns a list of boolean columns suitable for use as dummy variables in, for example,
 * regression analysis, select a column of categorical data must be encoded as a list of columns,
 * such that each column represents a single category and indicates whether it is present (1) or
 * not present (0)
 *
 * @return a list of {@link BooleanColumn}
 */
@Override
public List<BooleanColumn> getDummies() {
    List<BooleanColumn> results = new ArrayList<>();
    // createFromCsv the necessary columns
    for (Byte2ObjectMap.Entry<String> entry : keyToValueMap().byte2ObjectEntrySet()) {
        BooleanColumn column = BooleanColumn.create(entry.getValue());
        results.add(column);
    }
    // iterate over the values, updating the dummy variable columns as appropriate
    for (byte next : values) {
        String category = getValueForKey(next);
        for (BooleanColumn column : results) {
            if (category.equals(column.name())) {
                // TODO(lwhite): update the correct row more efficiently, by using set rather than add &
                // only
                // updating true
                column.append(true);
            } else {
                column.append(false);
            }
        }
    }
    return results;
}
Also used : Byte2ObjectMap(it.unimi.dsi.fastutil.bytes.Byte2ObjectMap) BooleanColumn(tech.tablesaw.api.BooleanColumn) ArrayList(java.util.ArrayList) ByteArrayList(it.unimi.dsi.fastutil.bytes.ByteArrayList)

Example 3 with BooleanColumn

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

the class ShortDictionaryMap method getDummies.

/**
 * Returns a list of boolean columns suitable for use as dummy variables in, for example,
 * regression analysis, select a column of categorical data must be encoded as a list of columns,
 * such that each column represents a single category and indicates whether it is present (1) or
 * not present (0)
 *
 * @return a list of {@link BooleanColumn}
 */
@Override
public List<BooleanColumn> getDummies() {
    List<BooleanColumn> results = new ArrayList<>();
    // createFromCsv the necessary columns
    for (Short2ObjectMap.Entry<String> entry : keyToValueMap().short2ObjectEntrySet()) {
        BooleanColumn column = BooleanColumn.create(entry.getValue());
        results.add(column);
    }
    // iterate over the values, updating the dummy variable columns as appropriate
    for (short next : values) {
        String category = getValueForKey(next);
        for (BooleanColumn column : results) {
            if (category.equals(column.name())) {
                // TODO(lwhite): update the correct row more efficiently, by using set rather than add &
                // only
                // updating true
                column.append(true);
            } else {
                column.append(false);
            }
        }
    }
    return results;
}
Also used : BooleanColumn(tech.tablesaw.api.BooleanColumn) ArrayList(java.util.ArrayList) ShortArrayList(it.unimi.dsi.fastutil.shorts.ShortArrayList) Short2ObjectMap(it.unimi.dsi.fastutil.shorts.Short2ObjectMap)

Example 4 with BooleanColumn

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

the class SqlResultSetReader method read.

/**
 * Returns a new table with the given tableName, constructed from the given result set
 *
 * @throws SQLException if there is a problem detected in the database
 */
public static Table read(ResultSet resultSet) throws SQLException {
    ResultSetMetaData metaData = resultSet.getMetaData();
    Table table = Table.create();
    // Setup the columns and add to the table
    for (int i = 1; i <= metaData.getColumnCount(); i++) {
        ColumnType type = getColumnType(metaData.getColumnType(i), metaData.getScale(i), metaData.getPrecision(i));
        Preconditions.checkState(type != null, "No column type found for %s as specified for column %s", metaData.getColumnType(i), metaData.getColumnName(i));
        Column<?> newColumn = type.create(metaData.getColumnLabel(i));
        table.addColumns(newColumn);
    }
    // Add the rows
    while (resultSet.next()) {
        for (int i = 1; i <= metaData.getColumnCount(); i++) {
            Column<?> column = // subtract 1 because results sets originate at 1 not 0
            table.column(i - 1);
            if (column instanceof ShortColumn) {
                appendToColumn(column, resultSet, resultSet.getShort(i));
            } else if (column instanceof IntColumn) {
                appendToColumn(column, resultSet, resultSet.getInt(i));
            } else if (column instanceof LongColumn) {
                appendToColumn(column, resultSet, resultSet.getLong(i));
            } else if (column instanceof FloatColumn) {
                appendToColumn(column, resultSet, resultSet.getFloat(i));
            } else if (column instanceof DoubleColumn) {
                appendToColumn(column, resultSet, resultSet.getDouble(i));
            } else if (column instanceof BooleanColumn) {
                appendToColumn(column, resultSet, resultSet.getBoolean(i));
            } else {
                column.appendObj(resultSet.getObject(i));
            }
        }
    }
    return table;
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) LongColumn(tech.tablesaw.api.LongColumn) Table(tech.tablesaw.api.Table) ColumnType(tech.tablesaw.api.ColumnType) DoubleColumn(tech.tablesaw.api.DoubleColumn) ShortColumn(tech.tablesaw.api.ShortColumn) BooleanColumn(tech.tablesaw.api.BooleanColumn) FloatColumn(tech.tablesaw.api.FloatColumn) IntColumn(tech.tablesaw.api.IntColumn)

Example 5 with BooleanColumn

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

the class IntDictionaryMap method getDummies.

/**
 * Returns a list of boolean columns suitable for use as dummy variables in, for example,
 * regression analysis, select a column of categorical data must be encoded as a list of columns,
 * such that each column represents a single category and indicates whether it is present (1) or
 * not present (0)
 *
 * @return a list of {@link BooleanColumn}
 */
@Override
public List<BooleanColumn> getDummies() {
    List<BooleanColumn> results = new ArrayList<>();
    // createFromCsv the necessary columns
    for (Int2ObjectMap.Entry<String> entry : keyToValueMap().int2ObjectEntrySet()) {
        BooleanColumn column = BooleanColumn.create(entry.getValue());
        results.add(column);
    }
    // iterate over the values, updating the dummy variable columns as appropriate
    for (int next : values) {
        String category = getValueForKey(next);
        for (BooleanColumn column : results) {
            if (category.equals(column.name())) {
                // TODO(lwhite): update the correct row more efficiently, by using set rather than add &
                // only
                // updating true
                column.append(true);
            } else {
                column.append(false);
            }
        }
    }
    return results;
}
Also used : BooleanColumn(tech.tablesaw.api.BooleanColumn) ArrayList(java.util.ArrayList) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) Int2ObjectMap(it.unimi.dsi.fastutil.ints.Int2ObjectMap)

Aggregations

BooleanColumn (tech.tablesaw.api.BooleanColumn)7 ArrayList (java.util.ArrayList)3 Selection (tech.tablesaw.selection.Selection)3 Byte2ObjectMap (it.unimi.dsi.fastutil.bytes.Byte2ObjectMap)1 ByteArrayList (it.unimi.dsi.fastutil.bytes.ByteArrayList)1 Int2ObjectMap (it.unimi.dsi.fastutil.ints.Int2ObjectMap)1 IntArrayList (it.unimi.dsi.fastutil.ints.IntArrayList)1 Short2ObjectMap (it.unimi.dsi.fastutil.shorts.Short2ObjectMap)1 ShortArrayList (it.unimi.dsi.fastutil.shorts.ShortArrayList)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 ColumnType (tech.tablesaw.api.ColumnType)1 DoubleColumn (tech.tablesaw.api.DoubleColumn)1 FloatColumn (tech.tablesaw.api.FloatColumn)1 IntColumn (tech.tablesaw.api.IntColumn)1 LongColumn (tech.tablesaw.api.LongColumn)1 ShortColumn (tech.tablesaw.api.ShortColumn)1 Table (tech.tablesaw.api.Table)1