use of tech.tablesaw.api.StringColumn in project symja_android_library by axkr.
the class CrossTab method rowPercents.
private static Table rowPercents(Table xTabCounts) {
Table pctTable = Table.create("Crosstab Row Proportions: ");
StringColumn labels = StringColumn.create(LABEL_COLUMN_NAME);
pctTable.addColumns(labels);
for (int i = 0; i < xTabCounts.rowCount(); i++) {
labels.append(xTabCounts.column(0).getString(i));
}
// create the new cols
DoubleColumn[] newColumns = new DoubleColumn[xTabCounts.columnCount() - 1];
for (int i = 1; i < xTabCounts.columnCount(); i++) {
Column<?> column = xTabCounts.column(i);
newColumns[i - 1] = DoubleColumn.create(column.name());
}
for (int i = 0; i < xTabCounts.rowCount(); i++) {
double rowTotal = xTabCounts.numberColumn(xTabCounts.columnCount() - 1).getDouble(i);
for (int c = 0; c < newColumns.length; c++) {
if (rowTotal == 0) {
newColumns[c].append(Double.NaN);
} else {
newColumns[c].append(xTabCounts.numberColumn(c + 1).getDouble(i) / rowTotal);
}
}
}
pctTable.addColumns(newColumns);
return pctTable;
}
use of tech.tablesaw.api.StringColumn in project symja_android_library by axkr.
the class Relation method structure.
public Table structure() {
Table t = Table.create("Structure of " + name());
IntColumn index = IntColumn.indexColumn("Index", columnCount(), 0);
StringColumn columnName = StringColumn.create("Column Name", columnCount());
StringColumn columnType = StringColumn.create("Column Type", columnCount());
t.addColumns(index);
t.addColumns(columnName);
t.addColumns(columnType);
for (int i = 0; i < columnCount(); i++) {
Column<?> column = this.columns().get(i);
columnType.set(i, column.type().name());
columnName.set(i, columnNames().get(i));
}
return t;
}
use of tech.tablesaw.api.StringColumn in project symja_android_library by axkr.
the class TimeMapFunctions method hourMinute.
/**
* Returns a StringColumn with the hour and minute-of-hour derived from this column concatenated
* into a String that will sort lexicographically in temporal order.
*
* <p>This simplifies the production of plots and tables that aggregate values into standard
* temporal units
*/
default StringColumn hourMinute() {
StringColumn newColumn = StringColumn.create(this.name() + " hour & minute");
for (int r = 0; r < this.size(); r++) {
int c1 = this.getIntInternal(r);
if (TimeColumn.valueIsMissing(c1)) {
newColumn.append(StringColumnType.missingValueIndicator());
} else {
String hm = Strings.padStart(String.valueOf(PackedLocalTime.getHour(c1)), 2, '0');
hm = hm + "-" + Strings.padStart(String.valueOf(PackedLocalTime.getMinute(c1)), 2, '0');
newColumn.append(hm);
}
}
return newColumn;
}
use of tech.tablesaw.api.StringColumn in project symja_android_library by axkr.
the class ShortDictionaryMap method countByCategory.
/**
*/
@Override
public Table countByCategory(String columnName) {
Table t = Table.create("Column: " + columnName);
StringColumn categories = StringColumn.create("Category");
IntColumn counts = IntColumn.create("Count");
// Now uses the keyToCount map
for (Map.Entry<Short, Integer> entry : keyToCount.short2IntEntrySet()) {
categories.append(getValueForKey(entry.getKey()));
counts.append(entry.getValue());
}
t.addColumns(categories);
t.addColumns(counts);
return t;
}
use of tech.tablesaw.api.StringColumn in project symja_android_library by axkr.
the class StringMapFunctions method capitalize.
/**
* Capitalizes each String changing the first character of each to title case as per {@link
* Character#toTitleCase(int)}, as if in a sentence. No other characters are changed.
*
* <pre>
* capitalize(null) = null
* capitalize("") = ""
* capitalize("cat") = "Cat"
* capitalize("cAt") = "CAt"
* capitalize("'cat'") = "'cat'"
* </pre>
*/
default StringColumn capitalize() {
StringColumn newColumn = StringColumn.create(name() + "[titleCase]");
for (int r = 0; r < size(); r++) {
String value = getString(r);
newColumn.append(StringUtils.capitalize(value));
}
return newColumn;
}
Aggregations