Modifying table structure
The meteorological station now needs to update its weather data table to accommodate new temperature forecasts. They want to add forecast temperatures while keeping the actual recorded temperatures for comparison purposes.
The Table, DoubleColumn, and StringColumn classes from Tablesaw have been imported for you.
This exercise is part of the course
Importing Data in Java
Exercise instructions
- Rename the "Temperature" column to "ActualTemp".
- Add a new "ForecastTemp" column to the table.
- Print the table structure.
- Print the first three rows.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
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.____(____));
}
}