CsvLoader { public DataFrame load(File file) { try (Reader r = new FileReader(file)) { return load(r); } catch (IOException e) { throw new RuntimeException("Error reading file: " + file, e); } } CsvLoader(); CsvLoader skipRows(int n); CsvLoader sampleRows(int size); CsvLoader sampleRows(int size, Random random); CsvLoader filterRows(String columnName, ValuePredicate<V> condition); CsvLoader filterRows(int columnPos, ValuePredicate<V> condition); @Deprecated CsvLoader columns(String... columns); CsvLoader header(String... columns); CsvLoader selectColumns(String... columns); CsvLoader selectColumns(int... columns); CsvLoader dropColumns(String... columns); CsvLoader columnType(int column, ValueMapper<String, ?> mapper); CsvLoader columnType(String column, ValueMapper<String, ?> mapper); CsvLoader intColumn(int column); CsvLoader intColumn(String column); CsvLoader intColumn(int column, int forNull); CsvLoader intColumn(String column, int forNull); CsvLoader longColumn(int column); CsvLoader longColumn(String column); CsvLoader longColumn(int column, long forNull); CsvLoader longColumn(String column, long forNull); CsvLoader doubleColumn(int column); CsvLoader doubleColumn(String column); CsvLoader doubleColumn(int column, double forNull); CsvLoader doubleColumn(String column, double forNull); CsvLoader booleanColumn(int column); CsvLoader booleanColumn(String column); CsvLoader numColumn(int column, Class<? extends Number> type); CsvLoader numColumn(String column, Class<? extends Number> type); CsvLoader dateColumn(int column); CsvLoader dateColumn(String column); CsvLoader dateTimeColumn(int column); CsvLoader dateTimeColumn(String column); CsvLoader dateColumn(int column, DateTimeFormatter formatter); CsvLoader dateColumn(String column, DateTimeFormatter formatter); CsvLoader dateTimeColumn(int column, DateTimeFormatter formatter); CsvLoader dateTimeColumn(String column, DateTimeFormatter formatter); CsvLoader format(CSVFormat format); CsvLoader emptyStringIsNull(); DataFrame load(File file); DataFrame load(String filePath); DataFrame load(Reader reader);  }
@Test public void testFromFile() { DataFrame df = new CsvLoader().load(inPath("f1.csv")); new DataFrameAsserts(df, "A", "b", "C") .expectHeight(2) .expectRow(0, "1", "2", "3") .expectRow(1, "4", "5", "6"); }
@Test public void testFromFile_DefaultFormat_Excel() { DataFrame df = new CsvLoader().load(inPath("from_excel.csv")); new DataFrameAsserts(df, "A", "b", "C") .expectHeight(2) .expectRow(0, "commas,quotes\"'", "-85.7", "3") .expectRow(1, "with, commas", "5.50001", "6"); }
@Test public void testFromFile_EmptyStringColumn() { DataFrame df = new CsvLoader() .load(inPath("strings_w_nulls.csv")); new DataFrameAsserts(df, "One", "Two") .expectHeight(2) .expectRow(0, "", "three") .expectRow(1, "five", ""); }
@Test public void testFromReader() { StringReader r = new StringReader("A,B" + System.lineSeparator() + "1,2" + System.lineSeparator() + "3,4"); DataFrame df = new CsvLoader().load(r); new DataFrameAsserts(df, "A", "B") .expectHeight(2) .expectRow(0, "1", "2") .expectRow(1, "3", "4"); }