Search in sources :

Example 21 with DoubleColumn

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

the class NumberMapFunctions method cumProd.

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

Example 22 with DoubleColumn

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

the class NumberMapFunctions method asPercent.

/**
 * Return the elements of this column as the percentages of their value relative to the sum of all
 * elements
 */
default DoubleColumn asPercent() {
    DoubleColumn pctColumn = DoubleColumn.create(name() + " percents", size());
    double total = sum();
    for (int i = 0; i < size(); i++) {
        if (total != 0) {
            pctColumn.set(i, (getDouble(i) / total) * 100);
        }
    }
    return pctColumn;
}
Also used : DoubleColumn(tech.tablesaw.api.DoubleColumn)

Example 23 with DoubleColumn

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

the class NumberMapFunctions method cumMax.

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

Example 24 with DoubleColumn

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

the class NumberMapFunctions method pctChange.

/**
 * Returns a new column with a percent change calculated
 */
default DoubleColumn pctChange() {
    DoubleColumn newColumn = DoubleColumn.create(name() + "[pctChange]", size());
    newColumn.setMissing(0);
    for (int i = 1; i < size(); i++) {
        newColumn.set(i, divide(getDouble(i), getDouble(i - 1)) - 1);
    }
    return newColumn;
}
Also used : DoubleColumn(tech.tablesaw.api.DoubleColumn)

Example 25 with DoubleColumn

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

the class NumberMapFunctions method subtract.

default DoubleColumn subtract(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, subtract(getDouble(r), column2.getDouble(r)));
    }
    return result;
}
Also used : DoubleColumn(tech.tablesaw.api.DoubleColumn)

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