use of tech.tablesaw.table.TableSlice 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.table.TableSlice in project symja_android_library by axkr.
the class DoubleArrays method to2dArray.
public static double[][] to2dArray(TableSliceGroup views, int columnNumber) {
int viewCount = views.size();
double[][] allVals = new double[viewCount][];
for (int viewNumber = 0; viewNumber < viewCount; viewNumber++) {
TableSlice view = views.get(viewNumber);
allVals[viewNumber] = new double[view.rowCount()];
NumericColumn<?> numberColumn = view.numberColumn(columnNumber);
for (int r = 0; r < view.rowCount(); r++) {
allVals[viewNumber][r] = numberColumn.getDouble(r);
}
}
return allVals;
}
Aggregations