use of tech.tablesaw.api.Table in project symja_android_library by axkr.
the class PivotTable method pivot.
public static Table pivot(Table table, CategoricalColumn<?> column1, CategoricalColumn<?> column2, NumericColumn<?> values, AggregateFunction<?, ?> aggregateFunction) {
TableSliceGroup tsg = table.splitOn(column1);
Table pivotTable = Table.create("Pivot: " + column1.name() + " x " + column2.name());
pivotTable.addColumns(column1.type().create(column1.name()));
List<String> valueColumnNames = getValueColumnNames(table, column2);
for (String colName : valueColumnNames) {
pivotTable.addColumns(DoubleColumn.create(colName));
}
int valueIndex = table.columnIndex(column2);
int keyIndex = table.columnIndex(column1);
String key;
for (TableSlice slice : tsg.getSlices()) {
key = String.valueOf(slice.get(0, keyIndex));
pivotTable.column(0).appendCell(key);
Map<String, Double> valueMap = getValueMap(column1, column2, values, valueIndex, slice, aggregateFunction);
for (String columnName : valueColumnNames) {
Double aDouble = valueMap.get(columnName);
NumericColumn<?> pivotValueColumn = pivotTable.numberColumn(columnName);
if (aDouble == null) {
pivotValueColumn.appendMissing();
} else {
pivotValueColumn.appendObj(aDouble);
}
}
}
return pivotTable;
}
use of tech.tablesaw.api.Table in project symja_android_library by axkr.
the class Summarizer method by.
/**
* Returns a summary of the records grouped into subsets of the same size, in the order they
* appear
*
* <p>All groups have the same number of records. If the final group has fewer than step records
* it is dropped.
*
* @param step the number or records to include in each group
*/
public Table by(int step) {
IntColumn groupColumn = assignToGroupsByStep(step);
Table t = getSummaryTable(groupColumn);
t.column(GROUP_COL_TEMP_NAME).setName("Group");
return t;
}
use of tech.tablesaw.api.Table in project symja_android_library by axkr.
the class Summarizer method summarizeForHaving.
/**
* Associates the columns to be summarized with the functions that match their type. All valid
* combinations are used
*
* @param group A table slice group
* @param selectionFunction Function that provides the filter for the having clause
* @return A table containing a row of summarized data for each group in the table slice group
*/
private Table summarizeForHaving(TableSliceGroup group, Function<Table, Selection> selectionFunction) {
List<Table> results = new ArrayList<>();
ArrayListMultimap<String, AggregateFunction<?, ?>> reductionMultimap = getAggregateFunctionMultimap();
for (String name : reductionMultimap.keys()) {
List<AggregateFunction<?, ?>> reductions = reductionMultimap.get(name);
Table groupTable = group.aggregate(name, reductions.toArray(new AggregateFunction<?, ?>[0]));
groupTable = groupTable.where(selectionFunction);
if (!groupTable.isEmpty()) {
results.add(groupTable);
}
}
return combineTables(results);
}
use of tech.tablesaw.api.Table in project symja_android_library by axkr.
the class AnalyticQuery method executeInPlace.
/**
* Executes the query and adds all the calculated columns directly to the source table.
*
* @throws IllegalArgumentException if any of the calculated columns have the same name as one of
* the columns in the FROM table.
*/
public void executeInPlace() {
Table result = execute();
table.concat(result);
}
use of tech.tablesaw.api.Table in project symja_android_library by axkr.
the class CrossTab method percents.
public static Table percents(Table table, String column1) {
Table countTable = counts(table, column1);
Table percentTable = Table.create(countTable.name());
percentTable.addColumns(countTable.column(0).copy());
IntColumn countsColumn = countTable.intColumn("Count");
DoubleColumn pctsColumn = DoubleColumn.create("Percents");
double sum = countsColumn.sum();
for (int i = 0; i < countsColumn.size(); i++) {
pctsColumn.append(countsColumn.getDouble(i) / sum);
}
percentTable.addColumns(pctsColumn);
return percentTable;
}
Aggregations