Tablesaw로 CSV 처리

Java에서 데이터 가져오기

Anthony Markham

VP Quant Developer

CSV 파일 읽기

  • read().csv()로 CSV 읽기
import tech.tablesaw.api.Table;
// Read in data
Table dataTable = Table.read().csv("data.csv");
  • 열 유형을 자동 감지하여 구조화된 Table 객체 생성 💡
Java에서 데이터 가져오기

CSV 읽기 옵션

  • 더 세밀한 제어에는 CsvReadOptions 사용
import tech.tablesaw.io.csv.CsvReadOptions;
CsvReadOptions options = CsvReadOptions.builder("data.csv")

.separator(';') // Use semicolon as delimiter
.header(true) // First row contains headers
.missingValueIndicator("N/A") // Treat "N/A" as missing data
.build();
// Load the table using the custom options Table table = Table.read().csv(options);
Java에서 데이터 가져오기

CSV 파일 쓰기

  • 기본 내보내기는 write().csv() 사용
  • Table 클래스로 호출
  • 열 유형과 구조 보존
  • 특수문자 자동 처리
// Write dataTable to output.csv
dataTable.write().csv("output.csv");
Java에서 데이터 가져오기

CSV 쓰기 옵션

  • 쓰기 옵션 지정에는 CsvWriteOptions 사용
CsvWriteOptions writeOptions = CsvWriteOptions
    .builder("output.csv")

.header(true) // Include column headers
.separator(';') // Use semicolon delimiter
.quoteAlways(true) // Quote all fields
.lineEnd("\r\n") // Windows-style line endings
.build();
// Write the CSV using the custom options
Table.write().csv(writeOptions);
Java에서 데이터 가져오기

CSV 워크플로

  • 전체 흐름: 읽기 -> 확인 -> 처리 -> 쓰기
  • 비파괴적 작업(새 파일 생성) 📁
// Read CSV, modify, and write back
Table students = Table.read().csv("students.csv");

// View structure
System.out.println(students.structure());

// Save as new file
students.write().csv("students_processed.csv");
Java에서 데이터 가져오기

연습해 봅시다!

Java에서 데이터 가져오기

Preparing Video For Download...