Java Code Examples for tech.tablesaw.api.Table#splitOn()
The following examples show how to use
tech.tablesaw.api.Table#splitOn() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimeSeriesPlot.java From tablesaw with Apache License 2.0 | 6 votes |
public static Figure create( String title, Table table, String dateColX, String yCol, String groupCol) { TableSliceGroup tables = table.splitOn(table.categoricalColumn(groupCol)); Layout layout = Layout.builder(title, dateColX, yCol).build(); ScatterTrace[] traces = new ScatterTrace[tables.size()]; for (int i = 0; i < tables.size(); i++) { List<Table> tableList = tables.asTableList(); Table t = tableList.get(i).sortOn(dateColX); traces[i] = ScatterTrace.builder(t.dateColumn(dateColX), t.numberColumn(yCol)) .showLegend(true) .name(tableList.get(i).name()) .mode(ScatterTrace.Mode.LINE) .build(); } return new Figure(layout, traces); }
Example 2
Source File: BubblePlot.java From tablesaw with Apache License 2.0 | 6 votes |
public static Figure create( String title, Table table, String xCol, String yCol, String sizeColumn, String groupCol) { TableSliceGroup tables = table.splitOn(table.categoricalColumn(groupCol)); Layout layout = Layout.builder(title, xCol, yCol).showLegend(true).build(); ScatterTrace[] traces = new ScatterTrace[tables.size()]; for (int i = 0; i < tables.size(); i++) { List<Table> tableList = tables.asTableList(); Marker marker = Marker.builder() .size(tableList.get(i).numberColumn(sizeColumn)) // .opacity(.75) .build(); traces[i] = ScatterTrace.builder( tableList.get(i).numberColumn(xCol), tableList.get(i).numberColumn(yCol)) .showLegend(true) .marker(marker) .name(tableList.get(i).name()) .build(); } return new Figure(layout, traces); }
Example 3
Source File: LinePlot.java From tablesaw with Apache License 2.0 | 6 votes |
public static Figure create( String title, Table table, String xCol, String yCol, String groupCol) { TableSliceGroup tables = table.splitOn(table.categoricalColumn(groupCol)); Layout layout = Layout.builder(title, xCol, yCol).showLegend(true).build(); ScatterTrace[] traces = new ScatterTrace[tables.size()]; for (int i = 0; i < tables.size(); i++) { List<Table> tableList = tables.asTableList(); traces[i] = ScatterTrace.builder( tableList.get(i).numberColumn(xCol), tableList.get(i).numberColumn(yCol)) .showLegend(true) .name(tableList.get(i).name()) .mode(ScatterTrace.Mode.LINE) .build(); } return new Figure(layout, traces); }
Example 4
Source File: ScatterPlot.java From tablesaw with Apache License 2.0 | 6 votes |
public static Figure create( String title, Table table, String xCol, String yCol, String groupCol) { TableSliceGroup tables = table.splitOn(table.categoricalColumn(groupCol)); Layout layout = Layout.builder(title, xCol, yCol).showLegend(true).build(); ScatterTrace[] traces = new ScatterTrace[tables.size()]; Marker marker = Marker.builder().opacity(OPACITY).build(); for (int i = 0; i < tables.size(); i++) { List<Table> tableList = tables.asTableList(); traces[i] = ScatterTrace.builder( tableList.get(i).numberColumn(xCol), tableList.get(i).numberColumn(yCol)) .showLegend(true) .marker(marker) .name(tableList.get(i).name()) .build(); } return new Figure(layout, traces); }
Example 5
Source File: SliceBugTests.java From tablesaw with Apache License 2.0 | 6 votes |
@Test public void sliceAsTableUsingDatesAfterFilteringDBLoadedTable() throws SQLException { Table salesTable = loadTableFromDB(); Table filteredTable = salesTable .select(salesTable.columnNames().toArray(new String[0])) .where( salesTable .instantColumn("sale_timestamp") .asLocalDateTimeColumn() .isAfter(LocalDateTime.of(2018, 1, 1, 13, 1, 3))); filteredTable.setName("filteredTable"); // work around TableSliceGroup slices = filteredTable.splitOn("countries"); slices.forEach( slice -> { assertFalse(slice.isEmpty()); }); }
Example 6
Source File: TimeSeriesPlot.java From tablesaw with Apache License 2.0 | 6 votes |
public static Figure create( String title, Table table, String dateColX, String yCol, String groupCol) { TableSliceGroup tables = table.splitOn(table.categoricalColumn(groupCol)); Layout layout = Layout.builder(title, dateColX, yCol).build(); ScatterTrace[] traces = new ScatterTrace[tables.size()]; for (int i = 0; i < tables.size(); i++) { List<Table> tableList = tables.asTableList(); Table t = tableList.get(i).sortOn(dateColX); traces[i] = ScatterTrace.builder(t.dateColumn(dateColX), t.numberColumn(yCol)) .showLegend(true) .name(tableList.get(i).name()) .mode(ScatterTrace.Mode.LINE) .build(); } return new Figure(layout, traces); }
Example 7
Source File: AreaPlot.java From tablesaw with Apache License 2.0 | 6 votes |
public static Figure create( String title, Table table, String xCol, String yCol, String groupCol) { TableSliceGroup tables = table.splitOn(table.categoricalColumn(groupCol)); Layout layout = Layout.builder(title, xCol, yCol).showLegend(true).build(); ScatterTrace[] traces = new ScatterTrace[tables.size()]; for (int i = 0; i < tables.size(); i++) { List<Table> tableList = tables.asTableList(); traces[i] = ScatterTrace.builder( tableList.get(i).numberColumn(xCol), tableList.get(i).numberColumn(yCol)) .showLegend(true) .name(tableList.get(i).name()) .mode(ScatterTrace.Mode.LINE) .fill(ScatterTrace.Fill.TO_NEXT_Y) .build(); } return new Figure(layout, traces); }
Example 8
Source File: BubblePlot.java From tablesaw with Apache License 2.0 | 6 votes |
public static Figure create( String title, Table table, String xCol, String yCol, String sizeColumn, String groupCol) { TableSliceGroup tables = table.splitOn(table.categoricalColumn(groupCol)); Layout layout = Layout.builder(title, xCol, yCol).showLegend(true).build(); ScatterTrace[] traces = new ScatterTrace[tables.size()]; for (int i = 0; i < tables.size(); i++) { List<Table> tableList = tables.asTableList(); Marker marker = Marker.builder() .size(tableList.get(i).numberColumn(sizeColumn)) // .opacity(.75) .build(); traces[i] = ScatterTrace.builder( tableList.get(i).numberColumn(xCol), tableList.get(i).numberColumn(yCol)) .showLegend(true) .marker(marker) .name(tableList.get(i).name()) .build(); } return new Figure(layout, traces); }
Example 9
Source File: LinePlot.java From tablesaw with Apache License 2.0 | 6 votes |
public static Figure create( String title, Table table, String xCol, String yCol, String groupCol) { TableSliceGroup tables = table.splitOn(table.categoricalColumn(groupCol)); Layout layout = Layout.builder(title, xCol, yCol).showLegend(true).build(); ScatterTrace[] traces = new ScatterTrace[tables.size()]; for (int i = 0; i < tables.size(); i++) { List<Table> tableList = tables.asTableList(); traces[i] = ScatterTrace.builder( tableList.get(i).numberColumn(xCol), tableList.get(i).numberColumn(yCol)) .showLegend(true) .name(tableList.get(i).name()) .mode(ScatterTrace.Mode.LINE) .build(); } return new Figure(layout, traces); }
Example 10
Source File: Scatter3DPlot.java From tablesaw with Apache License 2.0 | 6 votes |
public static Figure create( String title, Table table, String xCol, String yCol, String zCol, String groupCol) { TableSliceGroup tables = table.splitOn(table.categoricalColumn(groupCol)); Layout layout = standardLayout(title, xCol, yCol, zCol, true); Scatter3DTrace[] traces = new Scatter3DTrace[tables.size()]; for (int i = 0; i < tables.size(); i++) { List<Table> tableList = tables.asTableList(); traces[i] = Scatter3DTrace.builder( tableList.get(i).numberColumn(xCol), tableList.get(i).numberColumn(yCol), tableList.get(i).numberColumn(zCol)) .showLegend(true) .name(tableList.get(i).name()) .build(); } return new Figure(layout, traces); }
Example 11
Source File: AreaPlot.java From tablesaw with Apache License 2.0 | 6 votes |
public static Figure create( String title, Table table, String xCol, String yCol, String groupCol) { TableSliceGroup tables = table.splitOn(table.categoricalColumn(groupCol)); Layout layout = Layout.builder(title, xCol, yCol).showLegend(true).build(); ScatterTrace[] traces = new ScatterTrace[tables.size()]; for (int i = 0; i < tables.size(); i++) { List<Table> tableList = tables.asTableList(); traces[i] = ScatterTrace.builder( tableList.get(i).numberColumn(xCol), tableList.get(i).numberColumn(yCol)) .showLegend(true) .name(tableList.get(i).name()) .mode(ScatterTrace.Mode.LINE) .fill(ScatterTrace.Fill.TO_NEXT_Y) .build(); } return new Figure(layout, traces); }
Example 12
Source File: HistogramHorizontalExample.java From tablesaw with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { Table baseball = Table.read().csv("../data/baseball.csv"); Layout layout = Layout.builder() .title("Distribution of team batting averages") .barMode(Layout.BarMode.OVERLAY) .showLegend(true) .build(); TableSliceGroup groups = baseball.splitOn("league"); Table t1 = groups.get(0).asTable(); Table t2 = groups.get(1).asTable(); HistogramTrace trace1 = HistogramTrace.builder(t1.nCol("BA")) .name("American League") .opacity(.75) .nBinsY(24) .horizontal(true) .marker(Marker.builder().color("#FF4136").build()) .build(); HistogramTrace trace2 = HistogramTrace.builder(t2.nCol("BA")) .name("National League") .opacity(.75) .nBinsY(24) .horizontal(true) .marker(Marker.builder().color("#7FDBFF").build()) .build(); Plot.show(new Figure(layout, trace1, trace2)); }
Example 13
Source File: HistogramOverlayExample.java From tablesaw with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { Table baseball = Table.read().csv("../data/baseball.csv"); Layout layout = Layout.builder() .title("Distribution of team batting averages") .barMode(Layout.BarMode.OVERLAY) .showLegend(true) .build(); TableSliceGroup groups = baseball.splitOn("league"); Table t1 = groups.get(0).asTable(); HistogramTrace trace1 = HistogramTrace.builder(t1.nCol("BA")) .name("American Leage") .opacity(.75) .nBinsX(24) .marker(Marker.builder().color("#FF4136").build()) .build(); Table t2 = groups.get(1).asTable(); HistogramTrace trace2 = HistogramTrace.builder(t2.nCol("BA")) .name("National League") .opacity(.75) .nBinsX(24) .marker(Marker.builder().color("#7FDBFF").build()) .build(); Plot.show(new Figure(layout, trace1, trace2)); }
Example 14
Source File: DoubleArraysTest.java From tablesaw with Apache License 2.0 | 5 votes |
@Test public void testTo2dArray() throws Exception { Table table = Table.read().csv("../data/tornadoes_1950-2014.csv"); TableSliceGroup tableSliceGroup = table.splitOn("Scale"); int columnNuumber = table.columnIndex("Injuries"); DoubleArrays.to2dArray(tableSliceGroup, columnNuumber); }
Example 15
Source File: DoubleArraysTest.java From tablesaw with Apache License 2.0 | 5 votes |
@Test public void testTo2dArray() throws Exception { Table table = Table.read().csv("../data/tornadoes_1950-2014.csv"); TableSliceGroup tableSliceGroup = table.splitOn("Scale"); int columnNuumber = table.columnIndex("Injuries"); DoubleArrays.to2dArray(tableSliceGroup, columnNuumber); }
Example 16
Source File: HistogramOverlayExample.java From tablesaw with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { Table baseball = Table.read().csv("../data/baseball.csv"); Layout layout = Layout.builder() .title("Distribution of team batting averages") .barMode(Layout.BarMode.OVERLAY) .showLegend(true) .build(); TableSliceGroup groups = baseball.splitOn("league"); Table t1 = groups.get(0).asTable(); HistogramTrace trace1 = HistogramTrace.builder(t1.nCol("BA")) .name("American Leage") .opacity(.75) .nBinsX(24) .marker(Marker.builder().color("#FF4136").build()) .build(); Table t2 = groups.get(1).asTable(); HistogramTrace trace2 = HistogramTrace.builder(t2.nCol("BA")) .name("National League") .opacity(.75) .nBinsX(24) .marker(Marker.builder().color("#7FDBFF").build()) .build(); Plot.show(new Figure(layout, trace1, trace2)); }
Example 17
Source File: SliceBugTests.java From tablesaw with Apache License 2.0 | 5 votes |
@Test public void sliceColumnIsSameWhenRetrievedWithNameOrIndex() { Table table = constructTableFromArrays(); TableSliceGroup countrySplit = table.splitOn("countries"); for (TableSlice slice : countrySplit) { DoubleColumn priceColFromIndex = slice.doubleColumn(2); DoubleColumn priceColFromName = slice.doubleColumn("price"); assertTrue( Arrays.equals(priceColFromName.asDoubleArray(), priceColFromIndex.asDoubleArray()), "Columns should have same data"); } }
Example 18
Source File: Scatter3DPlot.java From tablesaw with Apache License 2.0 | 5 votes |
public static Figure create( String title, Table table, String xCol, String yCol, String zCol, String sizeColumn, String groupCol) { TableSliceGroup tables = table.splitOn(table.categoricalColumn(groupCol)); Layout layout = standardLayout(title, xCol, yCol, zCol, false); Scatter3DTrace[] traces = new Scatter3DTrace[tables.size()]; for (int i = 0; i < tables.size(); i++) { List<Table> tableList = tables.asTableList(); Marker marker = Marker.builder() .size(tableList.get(i).numberColumn(sizeColumn)) // .opacity(.75) .build(); traces[i] = Scatter3DTrace.builder( tableList.get(i).numberColumn(xCol), tableList.get(i).numberColumn(yCol), tableList.get(i).numberColumn(zCol)) .marker(marker) .showLegend(true) .name(tableList.get(i).name()) .build(); } return new Figure(layout, traces); }
Example 19
Source File: PivotTable.java From tablesaw with Apache License 2.0 | 4 votes |
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; }
Example 20
Source File: PivotTable.java From tablesaw with Apache License 2.0 | 4 votes |
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; }