Java Code Examples for tech.tablesaw.api.Table#transpose()

The following examples show how to use tech.tablesaw.api.Table#transpose() . 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: TableTransposeTest.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
@Test
void transposeUseFirstColumnForHeadings() {
  Table testTable =
      Table.create(
          TABLE_NAME,
          StringColumn.create("label", "row1", "row2", "row3"),
          DoubleColumn.create("value1", 1.0, 1.1, 1.2),
          DoubleColumn.create("value2", 2.0, 2.1, 2.2));
  Table result = testTable.transpose(false, true);

  assertTableEquals(
      Table.create(
          TABLE_NAME,
          DoubleColumn.create("row1", 1.0, 2.0),
          DoubleColumn.create("row2", 1.1, 2.1),
          DoubleColumn.create("row3", 1.2, 2.2)),
      result);
}
 
Example 2
Source File: TableTransposeTest.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
@Test
void transposeBooleans() {
  Table testTable =
      Table.create(
          TABLE_NAME,
          BooleanColumn.create("value1", true, true, true),
          BooleanColumn.create("value2", false, false, false));
  Table result = testTable.transpose();

  assertTableEquals(
      Table.create(
          TABLE_NAME,
          BooleanColumn.create("0", true, false),
          BooleanColumn.create("1", true, false),
          BooleanColumn.create("2", true, false)),
      result);
}
 
Example 3
Source File: TableTransposeTest.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
@Test
void transposeWithMissingData() {
  Table testTable =
      Table.create(
          TABLE_NAME,
          DoubleColumn.create("value1", 1.0, DoubleColumnType.missingValueIndicator(), 1.2),
          DoubleColumn.create("value2", 2.0, 2.1, 2.2));
  Table result = testTable.transpose();

  assertTableEquals(
      Table.create(
          TABLE_NAME,
          DoubleColumn.create("0", 1.0, 2.0),
          DoubleColumn.create("1", DoubleColumnType.missingValueIndicator(), 2.1),
          DoubleColumn.create("2", 1.2, 2.2)),
      result);
}
 
Example 4
Source File: TableTransposeTest.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
@Test
void transposeDoubles() {
  Table testTable =
      Table.create(
          TABLE_NAME,
          DoubleColumn.create("value1", 1.0, 1.1, 1.2),
          DoubleColumn.create("value2", 2.0, 2.1, 2.2));
  Table result = testTable.transpose();

  assertTableEquals(
      Table.create(
          TABLE_NAME,
          DoubleColumn.create("0", 1.0, 2.0),
          DoubleColumn.create("1", 1.1, 2.1),
          DoubleColumn.create("2", 1.2, 2.2)),
      result);
}
 
Example 5
Source File: TableTransposeTest.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
@Test
void transposeCanBeFullyReversible() {
  Table testTable =
      Table.create(
          TABLE_NAME,
          StringColumn.create("label", "row1", "row2", "row3"),
          DoubleColumn.create("value1", 1.0, 1.1, 1.2),
          DoubleColumn.create("value2", 2.0, 2.1, 2.2));
  Table result = testTable.transpose(true, true);

  assertTableEquals(
      Table.create(
          TABLE_NAME,
          StringColumn.create("label", "value1", "value2"),
          DoubleColumn.create("row1", 1.0, 2.0),
          DoubleColumn.create("row2", 1.1, 2.1),
          DoubleColumn.create("row3", 1.2, 2.2)),
      result);

  assertEquals(
      testTable.print(), result.transpose(true, true).print(), "Transpose is reversible");
}
 
Example 6
Source File: TableTransposeTest.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
@Test
void transposeStrings() {
  Table testTable =
      Table.create(
          TABLE_NAME,
          StringColumn.create("fruit", "apple", "banana", "pear"),
          StringColumn.create("colour", "red", "yellow", "green"));
  Table result = testTable.transpose();

  assertTableEquals(
      Table.create(
          TABLE_NAME,
          StringColumn.create("0", "apple", "red"),
          StringColumn.create("1", "banana", "yellow"),
          StringColumn.create("2", "pear", "green")),
      result);
}
 
Example 7
Source File: TableTransposeTest.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
@Test
void transposeUseFirstColumnForHeadings() {
  Table testTable =
      Table.create(
          TABLE_NAME,
          StringColumn.create("label", "row1", "row2", "row3"),
          DoubleColumn.create("value1", 1.0, 1.1, 1.2),
          DoubleColumn.create("value2", 2.0, 2.1, 2.2));
  Table result = testTable.transpose(false, true);

  assertTableEquals(
      Table.create(
          TABLE_NAME,
          DoubleColumn.create("row1", 1.0, 2.0),
          DoubleColumn.create("row2", 1.1, 2.1),
          DoubleColumn.create("row3", 1.2, 2.2)),
      result);
}
 
Example 8
Source File: TableTransposeTest.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
@Test
void transposeMixedTypesThrowsExceptionFirstColumnAsHeadings() {
  Table testTable =
      Table.create(
          TABLE_NAME,
          StringColumn.create("label", "row1", "row2", "row3"),
          DoubleColumn.create("value1", 1.0, 1.1, 1.2),
          StringColumn.create("colour", "red", "yellow", "green"));

  try {
    testTable.transpose(false, true);
    fail("Should throw an exception");
  } catch (IllegalArgumentException ex) {
    assertEquals(
        "This operation currently only supports tables where value columns are of the same type",
        ex.getMessage());
  }
}
 
Example 9
Source File: TableTransposeTest.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
@Test
void transposeMixedTypesThrowsException() {
  Table testTable =
      Table.create(
          TABLE_NAME,
          StringColumn.create("colour", "red", "yellow", "green"),
          DoubleColumn.create("value1", 1.0, 1.1, 1.2));

  try {
    testTable.transpose();
    fail("Should throw an exception");
  } catch (IllegalArgumentException ex) {
    assertEquals(
        "This operation currently only supports tables where value columns are of the same type",
        ex.getMessage());
  }
}
 
Example 10
Source File: TableTransposeTest.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
@Test
void transposeMixedTypesThrowsExceptionFirstColumnAsHeadings() {
  Table testTable =
      Table.create(
          TABLE_NAME,
          StringColumn.create("label", "row1", "row2", "row3"),
          DoubleColumn.create("value1", 1.0, 1.1, 1.2),
          StringColumn.create("colour", "red", "yellow", "green"));

  try {
    testTable.transpose(false, true);
    fail("Should throw an exception");
  } catch (IllegalArgumentException ex) {
    assertEquals(
        "This operation currently only supports tables where value columns are of the same type",
        ex.getMessage());
  }
}
 
Example 11
Source File: TableTransposeTest.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
@Test
void transposeIncludeColumnHeadingsAsFirstColumn() {
  Table testTable =
      Table.create(
          TABLE_NAME,
          DoubleColumn.create("value1", 1.0, 1.1, 1.2),
          DoubleColumn.create("value2", 2.0, 2.1, 2.2));
  Table result = testTable.transpose(true, false);

  assertTableEquals(
      Table.create(
          TABLE_NAME,
          StringColumn.create("0", "value1", "value2"),
          DoubleColumn.create("1", 1.0, 2.0),
          DoubleColumn.create("2", 1.1, 2.1),
          DoubleColumn.create("3", 1.2, 2.2)),
      result);
}
 
Example 12
Source File: TableTransposeTest.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
@Test
void transposeWithMissingData() {
  Table testTable =
      Table.create(
          TABLE_NAME,
          DoubleColumn.create("value1", 1.0, DoubleColumnType.missingValueIndicator(), 1.2),
          DoubleColumn.create("value2", 2.0, 2.1, 2.2));
  Table result = testTable.transpose();

  assertTableEquals(
      Table.create(
          TABLE_NAME,
          DoubleColumn.create("0", 1.0, 2.0),
          DoubleColumn.create("1", DoubleColumnType.missingValueIndicator(), 2.1),
          DoubleColumn.create("2", 1.2, 2.2)),
      result);
}
 
Example 13
Source File: TableTransposeTest.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
@Test
void transposeDoubles() {
  Table testTable =
      Table.create(
          TABLE_NAME,
          DoubleColumn.create("value1", 1.0, 1.1, 1.2),
          DoubleColumn.create("value2", 2.0, 2.1, 2.2));
  Table result = testTable.transpose();

  assertTableEquals(
      Table.create(
          TABLE_NAME,
          DoubleColumn.create("0", 1.0, 2.0),
          DoubleColumn.create("1", 1.1, 2.1),
          DoubleColumn.create("2", 1.2, 2.2)),
      result);
}
 
Example 14
Source File: TableTransposeTest.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
@Test
void transposeLongs() {
  Table testTable =
      Table.create(
          TABLE_NAME, LongColumn.create("value1", 1, 2, 3), LongColumn.create("value2", 4, 5, 6));
  Table result = testTable.transpose();

  assertTableEquals(
      Table.create(
          TABLE_NAME,
          LongColumn.create("0", 1L, 4L),
          LongColumn.create("1", 2L, 5L),
          LongColumn.create("2", 3L, 6L)),
      result);
}
 
Example 15
Source File: TableTransposeTest.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
@Test
void transposeIntegers() {
  Table testTable =
      Table.create(
          TABLE_NAME, IntColumn.create("value1", 1, 2, 3), IntColumn.create("value2", 4, 5, 6));
  Table result = testTable.transpose();

  assertTableEquals(
      Table.create(
          TABLE_NAME,
          IntColumn.create("0", 1, 4),
          IntColumn.create("1", 2, 5),
          IntColumn.create("2", 3, 6)),
      result);
}
 
Example 16
Source File: TableTransposeTest.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
@Test
void transposeFloats() {
  float float_1 = 1.0f;
  float float_2 = 2.0f;
  Table testTable =
      Table.create(
          TABLE_NAME,
          FloatColumn.create("value1", float_1),
          FloatColumn.create("value2", float_2));
  Table result = testTable.transpose();

  assertTableEquals(Table.create(TABLE_NAME, FloatColumn.create("0", float_1, float_2)), result);
}
 
Example 17
Source File: TableTransposeTest.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
@Test
void transposeFloats() {
  float float_1 = 1.0f;
  float float_2 = 2.0f;
  Table testTable =
      Table.create(
          TABLE_NAME,
          FloatColumn.create("value1", float_1),
          FloatColumn.create("value2", float_2));
  Table result = testTable.transpose();

  assertTableEquals(Table.create(TABLE_NAME, FloatColumn.create("0", float_1, float_2)), result);
}
 
Example 18
Source File: TableTransposeTest.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
@Test
void transposeIntegers() {
  Table testTable =
      Table.create(
          TABLE_NAME, IntColumn.create("value1", 1, 2, 3), IntColumn.create("value2", 4, 5, 6));
  Table result = testTable.transpose();

  assertTableEquals(
      Table.create(
          TABLE_NAME,
          IntColumn.create("0", 1, 4),
          IntColumn.create("1", 2, 5),
          IntColumn.create("2", 3, 6)),
      result);
}
 
Example 19
Source File: TableTransposeTest.java    From tablesaw with Apache License 2.0 5 votes vote down vote up
@Test
void transposeLongs() {
  Table testTable =
      Table.create(
          TABLE_NAME, LongColumn.create("value1", 1, 2, 3), LongColumn.create("value2", 4, 5, 6));
  Table result = testTable.transpose();

  assertTableEquals(
      Table.create(
          TABLE_NAME,
          LongColumn.create("0", 1L, 4L),
          LongColumn.create("1", 2L, 5L),
          LongColumn.create("2", 3L, 6L)),
      result);
}
 
Example 20
Source File: TableTransposeTest.java    From tablesaw with Apache License 2.0 4 votes vote down vote up
@Test
void transposeEmptyTable() {
  Table empty = Table.create(TABLE_NAME);
  Table result = empty.transpose();
  assertTableEquals(empty, result);
}