Search in sources :

Example 6 with Table

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

the class ASTDataset method selectColumns.

/**
 * Removes all columns except for those given in the <code>list</code>.
 *
 * @param list
 * @return
 */
private ASTDataset selectColumns(IAST list) {
    String[] strList = new String[list.argSize()];
    int[] vector = list.toIntVector();
    Table table = fTable;
    if (vector == null) {
        for (int i = 0; i < strList.length; i++) {
            strList[i] = list.get(i + 1).toString();
        }
        return newTablesawTable(table.select(strList));
    }
    List<String> columnNames = table.columnNames();
    for (int i = 0; i < vector.length; i++) {
        strList[i] = columnNames.get(vector[i] - 1);
    }
    return newTablesawTable(table.select(strList));
}
Also used : Table(tech.tablesaw.api.Table)

Example 7 with Table

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

the class ASTDataset method selectColumns.

/**
 * Removes all columns except for those given in the <code>column</code>.
 *
 * @param column
 * @return
 */
private ASTDataset selectColumns(int column) {
    String[] strList = new String[1];
    Table table = fTable;
    strList[0] = table.columnNames().get(column - 1);
    return newTablesawTable(table.select(strList));
}
Also used : Table(tech.tablesaw.api.Table)

Example 8 with Table

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

the class ASTDataset method select.

@Override
public IExpr select(IExpr row, IExpr column) {
    Table table = fTable;
    int[] span = column.isSpan(table.columnCount() - 1);
    if (span != null && span[2] == 1) {
        int columnStart = span[0] - 1;
        int columnEnd = span[1];
        String[] strList = new String[columnEnd - columnStart];
        List<String> columnNames = table.columnNames();
        for (int i = 0; i < strList.length; i++) {
            strList[i] = columnNames.get(i + columnStart);
        }
        table = table.select(strList);
    } else if (column.equals(S.All)) {
    } else if (column.isString()) {
        table = table.select(column.toString());
    } else if (column.isList()) {
        IAST list = (IAST) column;
        String[] strList = new String[list.argSize()];
        int[] vector = list.toIntVector();
        if (vector == null) {
            for (int i = 0; i < strList.length; i++) {
                strList[i] = list.get(i + 1).toString();
            }
        } else {
            List<String> columnNames = table.columnNames();
            for (int i = 0; i < vector.length; i++) {
                strList[i] = columnNames.get(vector[i] - 1);
            }
        }
        table = table.select(strList);
    } else {
        int colIndex = column.toIntDefault();
        if (colIndex > 0) {
            table = fTable.select(table.columnNames().get(colIndex - 1));
        } else {
            return F.NIL;
        }
    }
    span = row.isSpan(table.rowCount() - 1);
    if (span != null && span[2] == 1) {
        int rowStart = span[0] - 1;
        int rowEnd = span[1];
        table = table.inRange(rowStart, rowEnd);
        return newTablesawTable(table);
    } else if (row.equals(S.All)) {
        return newTablesawTable(table);
    } else if (row.isList()) {
        IAST list = (IAST) row;
        int[] iList = new int[list.argSize()];
        for (int i = 1; i < list.size(); i++) {
            iList[i - 1] = list.get(i).toIntDefault();
            if (iList[i - 1] <= 0) {
                return F.NIL;
            }
            iList[i - 1]--;
        }
        table = table.rows(iList);
        if (table.columnCount() == 1) {
            return Object2Expr.convertString(table.get(0, 0));
        }
        return newTablesawTable(table);
    } else {
        int rowIndex = row.toIntDefault();
        if (rowIndex > 0) {
            table = table.rows(rowIndex - 1);
            if (table.columnCount() == 1) {
                return Object2Expr.convertString(table.get(0, 0));
            }
            return newTablesawTable(table);
        }
    }
    return F.NIL;
}
Also used : Table(tech.tablesaw.api.Table) ArrayList(java.util.ArrayList) List(java.util.List) IAST(org.matheclipse.core.interfaces.IAST)

Example 9 with Table

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

the class ASTDataset method getValue.

/**
 * Return the value associated to the <code>key</code>. If no value is available return the <code>
 * defaultValue</code>
 *
 * @param key
 * @param defaultValue
 * @return
 */
@Override
public IExpr getValue(IExpr key, Supplier<IExpr> defaultValue) {
    final String keyName = key.toString();
    if (fTable.rowCount() == 1) {
        int columnIndex = fTable.columnIndex(keyName);
        if (columnIndex < 0) {
            return defaultValue.get();
        }
        return select(1, columnIndex + 1);
    }
    String[] strList = new String[] { keyName };
    Table table = fTable.select(strList);
    if (table.columnCount() == 0) {
        return defaultValue.get();
    }
    return newTablesawTable(table);
}
Also used : Table(tech.tablesaw.api.Table)

Example 10 with Table

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

the class PivotTable method getValueMap.

private static Map<String, Double> getValueMap(CategoricalColumn<?> column1, CategoricalColumn<?> column2, NumericColumn<?> values, int valueIndex, TableSlice slice, AggregateFunction<?, ?> function) {
    Table temp = slice.asTable();
    Table summary = temp.summarize(values.name(), function).by(column1.name(), column2.name());
    Map<String, Double> valueMap = new HashMap<>();
    NumericColumn<?> nc = summary.numberColumn(summary.columnCount() - 1);
    for (int i = 0; i < summary.rowCount(); i++) {
        valueMap.put(String.valueOf(summary.get(i, 1)), nc.getDouble(i));
    }
    return valueMap;
}
Also used : Table(tech.tablesaw.api.Table) HashMap(java.util.HashMap)

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