Search in sources :

Example 11 with DoubleColumn

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

the class NumberMapFunctions method divide.

default DoubleColumn divide(NumericColumn<?> column2) {
    int col1Size = size();
    int col2Size = column2.size();
    if (col1Size != col2Size)
        throw new IllegalArgumentException("The columns must have the same number of elements");
    DoubleColumn result = DoubleColumn.create(name() + " / " + column2.name(), col1Size);
    for (int r = 0; r < col1Size; r++) {
        result.set(r, divide(getDouble(r), column2.getDouble(r)));
    }
    return result;
}
Also used : DoubleColumn(tech.tablesaw.api.DoubleColumn)

Example 12 with DoubleColumn

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

the class NumberMapFunctions method cumMin.

/**
 * Returns a new column with a cumulative maximum calculated
 */
default DoubleColumn cumMin() {
    double min = DoubleColumnType.missingValueIndicator();
    DoubleColumn newColumn = DoubleColumn.create(name() + "[cumMin]", size());
    for (int i = 0; i < size(); i++) {
        double value = getDouble(i);
        if (!DoubleColumnType.valueIsMissing(value)) {
            min = DoubleColumnType.valueIsMissing(min) ? value : Math.min(min, value);
        }
        newColumn.set(i, min);
    }
    return newColumn;
}
Also used : DoubleColumn(tech.tablesaw.api.DoubleColumn)

Example 13 with DoubleColumn

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

the class NumberMapFunctions method remainder.

default DoubleColumn remainder(DoubleColumn column2) {
    DoubleColumn result = DoubleColumn.create(name() + " % " + column2.name(), size());
    for (int r = 0; r < size(); r++) {
        double val1 = getDouble(r);
        double val2 = column2.getDouble(r);
        if (DoubleColumnType.valueIsMissing(val1) || DoubleColumnType.valueIsMissing(val2)) {
            result.setMissing(r);
        } else {
            result.set(r, getDouble(r) % column2.getDouble(r));
        }
    }
    return result;
}
Also used : DoubleColumn(tech.tablesaw.api.DoubleColumn)

Example 14 with DoubleColumn

use of tech.tablesaw.api.DoubleColumn 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)

Example 15 with DoubleColumn

use of tech.tablesaw.api.DoubleColumn 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)

Aggregations

DoubleColumn (tech.tablesaw.api.DoubleColumn)32 Table (tech.tablesaw.api.Table)7 StringColumn (tech.tablesaw.api.StringColumn)5 TreeBasedTable (com.google.common.collect.TreeBasedTable)4 IntColumn (tech.tablesaw.api.IntColumn)2 LongColumn (tech.tablesaw.api.LongColumn)2 Splitter (com.google.common.base.Splitter)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 LocalDateTime (java.time.LocalDateTime)1 UnsupportedTemporalTypeException (java.time.temporal.UnsupportedTemporalTypeException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 CellDateFormatter (org.apache.poi.ss.format.CellDateFormatter)1 CellGeneralFormatter (org.apache.poi.ss.format.CellGeneralFormatter)1 CellNumberFormatter (org.apache.poi.ss.format.CellNumberFormatter)1 CellType (org.apache.poi.ss.usermodel.CellType)1 BooleanColumn (tech.tablesaw.api.BooleanColumn)1 ColumnType (tech.tablesaw.api.ColumnType)1 FloatColumn (tech.tablesaw.api.FloatColumn)1 ShortColumn (tech.tablesaw.api.ShortColumn)1