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());
}
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;
}
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;
}
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;
}
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;
}
Aggregations