Importing Data in Java
Anthony Markham
VP Quant Developer
DoubleColumn celsius = DoubleColumn.create("Celsius", 0, 10, 20, 30);DoubleColumn fahrenheit = celsius.map(c -> c * 9.0/5.0 + 32); table.addColumns(fahrenheit.setName("Fahrenheit"));
| Celsius | Fahrenheit |
|---|---|
| 0.0 | 32.0 |
| 10.0 | 50.0 |
| 20.0 | 68.0 |
| 30.0 | 86.0 |
// Find the total sales
double totalSales = table.doubleColumn("Sales").reduce(0, Double::sum);
250000
// Find the maximum
double largeSales = table.doubleColumn("Sales").reduce(0, (acc, x) -> acc + (x > 5000 ? 1 : 0));
68
DoubleColumn difference = DoubleColumn.create("Difference"); table.forEach(row -> { double celsius = row.getDouble("Celsius"); double fahrenheit = row.getDouble("Fahrenheit"); difference.append(fahrenheit - celsius); });table.addColumns(difference);
| Celsius | Fahrenheit | Difference |
|---|---|---|
| 0.0 | 32.0 | 32.0 |
| 10.0 | 50.0 | 40.0 |
| 20.0 | 68.0 | 48.0 |
Table result = originalTable .where(numberColumn("Age").isGreaterThan(18)) // Filter on Age > 18.addColumns( numberColumn("Income").map(i -> i * 1.1).setName("AdjustedIncome") );// Calculate average income double avgIncome = result.doubleColumn("AdjustedIncome") .reduce(0.0, Double::sum) / result.rowCount();
map() - apply a function to transform column valuesforEach() - iterate through rows to access multiple columnsreduce() - aggregate and summarize data into single values
Importing Data in Java