테이블 구조 수정하기
기상 관측소에서 새로운 기온 예보를 반영하기 위해 기존 날씨 데이터 테이블을 업데이트하려고 합니다. 실제 관측 기온은 비교를 위해 그대로 두면서 예보 기온을 추가하려고 합니다.
Tablesaw의 Table, DoubleColumn, 그리고 StringColumn 클래스는 이미 임포트되어 있습니다.
이 연습은 강의의 일부입니다
Java에서 데이터 가져오기
연습 안내
- "Temperature" 열의 이름을 "ActualTemp"로 바꾸세요.
- 테이블에 새로운 "ForecastTemp" 열을 추가하세요.
- 테이블 구조를 출력하세요.
- 처음 세 행을 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
public class ModifyWeatherTable {
public static void main(String[] args) {
StringColumn days = StringColumn.create("Day",
"Monday", "Tuesday", "Wednesday");
DoubleColumn temperatures = DoubleColumn.create("Temperature",
22.5, 24.0, 23.2);
DoubleColumn precipitation = DoubleColumn.create("Precipitation",
0.0, 2.5, 5.2);
Table weatherData = Table.create("WeatherData")
.addColumns(days, temperatures, precipitation);
// Rename the Temperature column
weatherData.____("Temperature").____("____");
// Add a new ForecastTemp column
DoubleColumn forecastTemps = DoubleColumn.create("ForecastTemp",
23.0, 25.2, 22.8);
weatherData = weatherData.____(forecastTemps);
// Print the table structure
System.out.println(weatherData.____());
// Print the first three rows
System.out.println(weatherData.____(____));
}
}