Search in sources :

Example 1 with Column

use of tech.tablesaw.columns.Column in project symja_android_library by axkr.

the class ASTDataset method newAssociationOfAssociations.

/**
 * Create a <code>Dataset</code> object from a (head-)association <code>&lt;|...|&gt;</code> of
 * (sub-)associations. Each key in the (head-)association is used in the first column the
 * (sub-)association represents the other columns of a row in the <code>Dataset</code>. The
 * left-hand-side of each singular rule in a (sub-)association was assumed to be the name of the
 * resulting <code>Dataset</code> columns. Identical names maps the right-hand-side values of the
 * rule to the same columns in the resulting dataset.
 *
 * @param assocOfAssociations
 * @return {@link F#NIL} if the <code>Dataset</code> cannot be created
 */
public static IExpr newAssociationOfAssociations(IAssociation assocOfAssociations) {
    // 1. phase: build up column names; reserve 1 column for header assoc
    List<String> colNames = new ArrayList<String>();
    Set<String> colNamesSet = new HashSet<String>();
    colNamesSet.add("");
    colNames.add("");
    for (int i = 1; i < assocOfAssociations.size(); i++) {
        IAssociation assoc = (IAssociation) assocOfAssociations.get(i);
        for (int j = 1; j < assoc.size(); j++) {
            IAST rule = assoc.getRule(j);
            String columnName = rule.first().toString();
            if (!colNamesSet.contains(columnName)) {
                colNamesSet.add(columnName);
                colNames.add(columnName);
            }
        }
    }
    if (colNames.size() > 0) {
        // 2. phase: define the columns
        Table table = Table.create();
        Column<?>[] cols = new Column<?>[colNames.size()];
        for (int i = 0; i < colNames.size(); i++) {
            cols[i] = ExprColumn.create(colNames.get(i));
        }
        table.addColumns(cols);
        // 3. phase: add the values
        for (int i = 1; i < assocOfAssociations.size(); i++) {
            IExpr rule = assocOfAssociations.getRule(i);
            IAssociation assoc = (IAssociation) rule.second();
            Row row = table.appendRow();
            row.setExpr("", rule.first());
            for (int j = 1; j < assoc.size(); j++) {
                rule = assoc.getRule(j);
                String columnName = rule.first().toString();
                IExpr value = rule.second();
                row.setExpr(columnName, value);
            }
        }
        return newTablesawTable(table);
    }
    return F.NIL;
}
Also used : IAssociation(org.matheclipse.core.interfaces.IAssociation) Table(tech.tablesaw.api.Table) ArrayList(java.util.ArrayList) Column(tech.tablesaw.columns.Column) ExprColumn(tech.tablesaw.api.ExprColumn) IAST(org.matheclipse.core.interfaces.IAST) IExpr(org.matheclipse.core.interfaces.IExpr) Row(tech.tablesaw.api.Row) HashSet(java.util.HashSet)

Example 2 with Column

use of tech.tablesaw.columns.Column in project symja_android_library by axkr.

the class ArgumentList method createEmptyDestinationColumns.

/**
 * @return an ordered list of new columns this analytic query will generate.
 */
List<Column<?>> createEmptyDestinationColumns(int rowCount) {
    List<Column<?>> newColumns = new ArrayList<>();
    for (String toColumn : newColumnNames) {
        FunctionCall<? extends FunctionMetaData> functionCall = Stream.of(aggregateFunctions.get(toColumn), numberingFunctions.get(toColumn)).filter(java.util.Objects::nonNull).findFirst().get();
        ColumnType type = functionCall.function.returnType();
        Column<?> resultColumn = type.create(toColumn);
        newColumns.add(resultColumn);
        for (int i = 0; i < rowCount; i++) {
            resultColumn.appendMissing();
        }
    }
    return newColumns;
}
Also used : ColumnType(tech.tablesaw.api.ColumnType) Column(tech.tablesaw.columns.Column) ArrayList(java.util.ArrayList) Objects(com.google.common.base.Objects)

Example 3 with Column

use of tech.tablesaw.columns.Column in project symja_android_library by axkr.

the class Table method append.

@SuppressWarnings({ "rawtypes", "unchecked" })
public Table append(Table tableToAppend) {
    for (final Column column : columnList) {
        final Column columnToAppend = tableToAppend.column(column.name());
        column.append(columnToAppend);
    }
    return this;
}
Also used : Column(tech.tablesaw.columns.Column)

Example 4 with Column

use of tech.tablesaw.columns.Column in project symja_android_library by axkr.

the class Rows method copyRowsToTable.

/**
 * Copies the rows indicated by the row index values in the given array from oldTable to newTable
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void copyRowsToTable(int[] rows, Table oldTable, Table newTable) {
    for (int columnIndex = 0; columnIndex < oldTable.columnCount(); columnIndex++) {
        Column oldColumn = oldTable.column(columnIndex);
        int r = 0;
        for (int i : rows) {
            newTable.column(columnIndex).set(r, oldColumn, i);
            r++;
        }
    }
}
Also used : Column(tech.tablesaw.columns.Column)

Example 5 with Column

use of tech.tablesaw.columns.Column in project symja_android_library by axkr.

the class Rows method copyRowsToTable.

/**
 * Copies the rows indicated by the row index values in the given selection from oldTable to
 * newTable
 */
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void copyRowsToTable(Selection rows, Table oldTable, Table newTable) {
    for (int columnIndex = 0; columnIndex < oldTable.columnCount(); columnIndex++) {
        Column oldColumn = oldTable.column(columnIndex);
        int r = 0;
        for (int i : rows) {
            newTable.column(columnIndex).set(r, oldColumn, i);
            r++;
        }
    }
}
Also used : Column(tech.tablesaw.columns.Column)

Aggregations

Column (tech.tablesaw.columns.Column)17 ArrayList (java.util.ArrayList)7 Table (tech.tablesaw.api.Table)7 ColumnType (tech.tablesaw.api.ColumnType)6 Row (tech.tablesaw.api.Row)4 List (java.util.List)3 IExpr (org.matheclipse.core.interfaces.IExpr)3 ExprColumn (tech.tablesaw.api.ExprColumn)3 Streams (com.google.common.collect.Streams)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 NoSuchElementException (java.util.NoSuchElementException)2 Beta (com.google.common.annotations.Beta)1 Objects (com.google.common.base.Objects)1 Preconditions (com.google.common.base.Preconditions)1 Strings (com.google.common.base.Strings)1 Lists (com.google.common.collect.Lists)1