use of tech.tablesaw.api.IntColumn in project symja_android_library by axkr.
the class Summarizer method having.
public Table having(Function<Table, Selection> selection) {
Preconditions.checkState(groupColumnNames.length > 0, "Cannot perform having() on summary that has not been grouped first");
if (groupColumnNames[0].equals(GROUP_COL_TEMP_NAME)) {
IntColumn groupColumn = temp.intColumn(GROUP_COL_TEMP_NAME);
TableSliceGroup group = StandardTableSliceGroup.create(temp, groupColumn);
return summarizeForHaving(group, selection);
} else {
TableSliceGroup group = StandardTableSliceGroup.create(temp, groupColumnNames);
return summarizeForHaving(group, selection);
}
}
use of tech.tablesaw.api.IntColumn in project symja_android_library by axkr.
the class Summarizer method assignToGroupsByStep.
private IntColumn assignToGroupsByStep(int step) {
IntColumn groupColumn = IntColumn.create(GROUP_COL_TEMP_NAME, temp.rowCount());
temp.addColumns(groupColumn);
int groupId = 1;
int withinGroupCount = 0;
Row row = new Row(temp);
while (row.hasNext()) {
row.next();
if (withinGroupCount < step) {
withinGroupCount++;
groupColumn.set(row.getRowNumber(), groupId);
} else {
groupId++;
groupColumn.set(row.getRowNumber(), groupId);
withinGroupCount = 1;
}
}
int lastGroupSize = temp.where(numberColumn(GROUP_COL_TEMP_NAME).isEqualTo(groupId)).rowCount();
if (lastGroupSize < step) {
temp = temp.dropWhere(numberColumn(GROUP_COL_TEMP_NAME).isEqualTo(groupId));
}
temp.addColumns(IntColumn.indexColumn("index", temp.rowCount(), 1));
return groupColumn;
}
use of tech.tablesaw.api.IntColumn in project symja_android_library by axkr.
the class Summarizer method groupBy.
public Summarizer groupBy(int step) {
IntColumn groupColumn = assignToGroupsByStep(step);
if (tableDoesNotContain(groupColumn.name(), temp)) {
temp.addColumns(groupColumn);
}
groupColumnNames = new String[] { GROUP_COL_TEMP_NAME };
return this;
}
use of tech.tablesaw.api.IntColumn 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.IntColumn 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