use of tech.tablesaw.api.Table in project symja_android_library by axkr.
the class ASTDataset method selectColumns.
/**
* Removes all columns except for those given in the <code>list</code>.
*
* @param list
* @return
*/
private ASTDataset selectColumns(IAST list) {
String[] strList = new String[list.argSize()];
int[] vector = list.toIntVector();
Table table = fTable;
if (vector == null) {
for (int i = 0; i < strList.length; i++) {
strList[i] = list.get(i + 1).toString();
}
return newTablesawTable(table.select(strList));
}
List<String> columnNames = table.columnNames();
for (int i = 0; i < vector.length; i++) {
strList[i] = columnNames.get(vector[i] - 1);
}
return newTablesawTable(table.select(strList));
}
use of tech.tablesaw.api.Table in project symja_android_library by axkr.
the class ASTDataset method selectColumns.
/**
* Removes all columns except for those given in the <code>column</code>.
*
* @param column
* @return
*/
private ASTDataset selectColumns(int column) {
String[] strList = new String[1];
Table table = fTable;
strList[0] = table.columnNames().get(column - 1);
return newTablesawTable(table.select(strList));
}
use of tech.tablesaw.api.Table in project symja_android_library by axkr.
the class ASTDataset method select.
@Override
public IExpr select(IExpr row, IExpr column) {
Table table = fTable;
int[] span = column.isSpan(table.columnCount() - 1);
if (span != null && span[2] == 1) {
int columnStart = span[0] - 1;
int columnEnd = span[1];
String[] strList = new String[columnEnd - columnStart];
List<String> columnNames = table.columnNames();
for (int i = 0; i < strList.length; i++) {
strList[i] = columnNames.get(i + columnStart);
}
table = table.select(strList);
} else if (column.equals(S.All)) {
} else if (column.isString()) {
table = table.select(column.toString());
} else if (column.isList()) {
IAST list = (IAST) column;
String[] strList = new String[list.argSize()];
int[] vector = list.toIntVector();
if (vector == null) {
for (int i = 0; i < strList.length; i++) {
strList[i] = list.get(i + 1).toString();
}
} else {
List<String> columnNames = table.columnNames();
for (int i = 0; i < vector.length; i++) {
strList[i] = columnNames.get(vector[i] - 1);
}
}
table = table.select(strList);
} else {
int colIndex = column.toIntDefault();
if (colIndex > 0) {
table = fTable.select(table.columnNames().get(colIndex - 1));
} else {
return F.NIL;
}
}
span = row.isSpan(table.rowCount() - 1);
if (span != null && span[2] == 1) {
int rowStart = span[0] - 1;
int rowEnd = span[1];
table = table.inRange(rowStart, rowEnd);
return newTablesawTable(table);
} else if (row.equals(S.All)) {
return newTablesawTable(table);
} else if (row.isList()) {
IAST list = (IAST) row;
int[] iList = new int[list.argSize()];
for (int i = 1; i < list.size(); i++) {
iList[i - 1] = list.get(i).toIntDefault();
if (iList[i - 1] <= 0) {
return F.NIL;
}
iList[i - 1]--;
}
table = table.rows(iList);
if (table.columnCount() == 1) {
return Object2Expr.convertString(table.get(0, 0));
}
return newTablesawTable(table);
} else {
int rowIndex = row.toIntDefault();
if (rowIndex > 0) {
table = table.rows(rowIndex - 1);
if (table.columnCount() == 1) {
return Object2Expr.convertString(table.get(0, 0));
}
return newTablesawTable(table);
}
}
return F.NIL;
}
use of tech.tablesaw.api.Table in project symja_android_library by axkr.
the class ASTDataset method getValue.
/**
* Return the value associated to the <code>key</code>. If no value is available return the <code>
* defaultValue</code>
*
* @param key
* @param defaultValue
* @return
*/
@Override
public IExpr getValue(IExpr key, Supplier<IExpr> defaultValue) {
final String keyName = key.toString();
if (fTable.rowCount() == 1) {
int columnIndex = fTable.columnIndex(keyName);
if (columnIndex < 0) {
return defaultValue.get();
}
return select(1, columnIndex + 1);
}
String[] strList = new String[] { keyName };
Table table = fTable.select(strList);
if (table.columnCount() == 0) {
return defaultValue.get();
}
return newTablesawTable(table);
}
use of tech.tablesaw.api.Table in project symja_android_library by axkr.
the class PivotTable method getValueMap.
private static Map<String, Double> getValueMap(CategoricalColumn<?> column1, CategoricalColumn<?> column2, NumericColumn<?> values, int valueIndex, TableSlice slice, AggregateFunction<?, ?> function) {
Table temp = slice.asTable();
Table summary = temp.summarize(values.name(), function).by(column1.name(), column2.name());
Map<String, Double> valueMap = new HashMap<>();
NumericColumn<?> nc = summary.numberColumn(summary.columnCount() - 1);
for (int i = 0; i < summary.rowCount(); i++) {
valueMap.put(String.valueOf(summary.get(i, 1)), nc.getDouble(i));
}
return valueMap;
}
Aggregations