Java Code Examples for tech.tablesaw.api.Table#xTabColumnPercents()
The following examples show how to use
tech.tablesaw.api.Table#xTabColumnPercents() .
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: CrossTabs.java From tablesaw with Apache License 2.0 | 4 votes |
@Override public void run() throws IOException { // @@ intro_block // preparation: load the data, and add a string column to hold the months in the date col Table table = Table.read().csv("../data/bush.csv"); StringColumn month = table.dateColumn("date").month(); month.setName("month"); table.addColumns(month); // perform the crossTab operation Table counts = table.xTabCounts("month", "who"); System.out.println(counts); // @@ intro_block outputWriter.write(counts, "intro_block"); // @@ who_counts Table whoCounts = table.xTabCounts("who"); // @@ who_counts outputWriter.write(whoCounts, "who_counts"); // @@ who_percents Table whoPercents = table.xTabPercents("who"); // @@ who_percents // @@ who_percents_format whoPercents .columnsOfType(ColumnType.DOUBLE) // format to display as percents .forEach(x -> ((NumberColumn) x).setPrintFormatter(NumberColumnFormatter.percent(0))); // @@ who_percents_format outputWriter.write(whoPercents, "who_percents_format"); // @@ table_percents Table tablePercents = table.xTabTablePercents("month", "who"); tablePercents .columnsOfType(ColumnType.DOUBLE) .forEach(x -> ((NumberColumn) x).setPrintFormatter(NumberColumnFormatter.percent(1))); // @@ table_percents outputWriter.write(tablePercents, "table_percents"); // @@ column_percents Table columnPercents = table.xTabColumnPercents("month", "who"); // @@ column_percents columnPercents .columnsOfType(ColumnType.DOUBLE) .forEach(x -> ((NumberColumn) x).setPrintFormatter(NumberColumnFormatter.percent(0))); outputWriter.write(columnPercents, "column_percents"); // @@ row_percents Table rowPercents = table.xTabRowPercents("month", "who"); // @@ row_percents rowPercents .columnsOfType(ColumnType.DOUBLE) .forEach(x -> ((NumberColumn) x).setPrintFormatter(NumberColumnFormatter.percent(0))); outputWriter.write(rowPercents, "row_percents"); }
Example 2
Source File: CrossTabsExample.java From tablesaw with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { Table table = Table.read().csv("../data/bush.csv"); StringColumn month = table.dateColumn("date").month(); table.addColumns(month.setName("month")); // two variable counts Table counts = table.xTabCounts("month", "who"); // make table print as integers with no decimals instead of the raw doubles it holds counts .columnsOfType(ColumnType.DOUBLE) .forEach(x -> ((NumberColumn<?, ?>) x).setPrintFormatter(NumberColumnFormatter.ints())); // single variable counts Table whoCounts = table.xTabCounts("who"); whoCounts .columnsOfType(ColumnType.DOUBLE) .forEach(x -> ((NumberColumn<?, ?>) x).setPrintFormatter(NumberColumnFormatter.ints())); // single variable percents Table whoPercents = table.xTabPercents("who"); whoPercents .columnsOfType(ColumnType.DOUBLE) .forEach(x -> ((NumberColumn<?, ?>) x).setPrintFormatter(NumberColumnFormatter.percent(0))); // table percents Table tablePercents = table.xTabTablePercents("month", "who"); tablePercents .columnsOfType(ColumnType.DOUBLE) .forEach(x -> ((NumberColumn<?, ?>) x).setPrintFormatter(NumberColumnFormatter.percent(1))); // column percents Table columnPercents = table.xTabColumnPercents("month", "who"); columnPercents .columnsOfType(ColumnType.DOUBLE) .forEach(x -> ((NumberColumn<?, ?>) x).setPrintFormatter(NumberColumnFormatter.percent(0))); // row percents Table rowPercents = table.xTabRowPercents("month", "who"); rowPercents .columnsOfType(ColumnType.DOUBLE) .forEach(x -> ((NumberColumn<?, ?>) x).setPrintFormatter(NumberColumnFormatter.percent(0))); }
Example 3
Source File: CrossTabs.java From tablesaw with Apache License 2.0 | 4 votes |
@Override public void run() throws IOException { // @@ intro_block // preparation: load the data, and add a string column to hold the months in the date col Table table = Table.read().csv("../data/bush.csv"); StringColumn month = table.dateColumn("date").month(); month.setName("month"); table.addColumns(month); // perform the crossTab operation Table counts = table.xTabCounts("month", "who"); System.out.println(counts); // @@ intro_block outputWriter.write(counts, "intro_block"); // @@ who_counts Table whoCounts = table.xTabCounts("who"); // @@ who_counts outputWriter.write(whoCounts, "who_counts"); // @@ who_percents Table whoPercents = table.xTabPercents("who"); // @@ who_percents // @@ who_percents_format whoPercents .columnsOfType(ColumnType.DOUBLE) // format to display as percents .forEach(x -> ((NumberColumn) x).setPrintFormatter(NumberColumnFormatter.percent(0))); // @@ who_percents_format outputWriter.write(whoPercents, "who_percents_format"); // @@ table_percents Table tablePercents = table.xTabTablePercents("month", "who"); tablePercents .columnsOfType(ColumnType.DOUBLE) .forEach(x -> ((NumberColumn) x).setPrintFormatter(NumberColumnFormatter.percent(1))); // @@ table_percents outputWriter.write(tablePercents, "table_percents"); // @@ column_percents Table columnPercents = table.xTabColumnPercents("month", "who"); // @@ column_percents columnPercents .columnsOfType(ColumnType.DOUBLE) .forEach(x -> ((NumberColumn) x).setPrintFormatter(NumberColumnFormatter.percent(0))); outputWriter.write(columnPercents, "column_percents"); // @@ row_percents Table rowPercents = table.xTabRowPercents("month", "who"); // @@ row_percents rowPercents .columnsOfType(ColumnType.DOUBLE) .forEach(x -> ((NumberColumn) x).setPrintFormatter(NumberColumnFormatter.percent(0))); outputWriter.write(rowPercents, "row_percents"); }
Example 4
Source File: CrossTabsExample.java From tablesaw with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { Table table = Table.read().csv("../data/bush.csv"); StringColumn month = table.dateColumn("date").month(); table.addColumns(month.setName("month")); // two variable counts Table counts = table.xTabCounts("month", "who"); // make table print as integers with no decimals instead of the raw doubles it holds counts .columnsOfType(ColumnType.DOUBLE) .forEach(x -> ((NumberColumn<?, ?>) x).setPrintFormatter(NumberColumnFormatter.ints())); // single variable counts Table whoCounts = table.xTabCounts("who"); whoCounts .columnsOfType(ColumnType.DOUBLE) .forEach(x -> ((NumberColumn<?, ?>) x).setPrintFormatter(NumberColumnFormatter.ints())); // single variable percents Table whoPercents = table.xTabPercents("who"); whoPercents .columnsOfType(ColumnType.DOUBLE) .forEach(x -> ((NumberColumn<?, ?>) x).setPrintFormatter(NumberColumnFormatter.percent(0))); // table percents Table tablePercents = table.xTabTablePercents("month", "who"); tablePercents .columnsOfType(ColumnType.DOUBLE) .forEach(x -> ((NumberColumn<?, ?>) x).setPrintFormatter(NumberColumnFormatter.percent(1))); // column percents Table columnPercents = table.xTabColumnPercents("month", "who"); columnPercents .columnsOfType(ColumnType.DOUBLE) .forEach(x -> ((NumberColumn<?, ?>) x).setPrintFormatter(NumberColumnFormatter.percent(0))); // row percents Table rowPercents = table.xTabRowPercents("month", "who"); rowPercents .columnsOfType(ColumnType.DOUBLE) .forEach(x -> ((NumberColumn<?, ?>) x).setPrintFormatter(NumberColumnFormatter.percent(0))); }