Datenbereinigung in Java
Dennis Lee
Software Engineer
| Books | Authors | Language | First_Published | Sales_in_Millions | Average_Price |
|---|---|---|---|---|---|
| A Tale of Two Cities | Charles Dickens | English | 1859 | 200.0 | 12.99 |
| The Little Prince (Le Petit Prince) | Antoine de Saint-Exupéry | French | 1943 | 200.0 | 15.50 |
| Harry Potter and the Philosopher's Stone | J. K. Rowling | English | 1997 | 120.0 | 19.99 |
| And Then There Were None | Agatha Christie | English | 1939 | 100.0 | 14.95 |
import tech.tablesaw.api.Table;
import tech.tablesaw.api.DoubleColumn;
import tech.tablesaw.api.StringColumn;
// Load CSV file into Tablesaw table
Table books = Table.read().csv("bestsellers.csv");
// Get basic table information: row count, column count, column names
System.out.println("Zeilenanzahl: " + books.rowCount());
System.out.println("Spaltenanzahl: " + books.columnCount());
System.out.println("Spaltennamen: " + books.columnNames());
Zeilenanzahl: 290
Spaltenanzahl: 6
Spaltennamen: [Books, Authors, Language, First_Published, Sales_in_millions]
for (String columnName : books.columnNames()) {// Get column by name and count missing values (nulls) in that column int missing = books.column(columnName).countMissing();System.out.println(columnName + " fehlende Werte: " + missing); }
Books fehlende Werte: 0
Authors fehlende Werte: 0
Language fehlende Werte: 0
First_Published fehlende Werte: 0
Sales_in_millions fehlende Werte: 2
Average_Price fehlende Werte: 0
// countBy() creates new table with unique values and their frequencies
Table languageCounts = books.countBy("Language");
System.out.println("Sprachverteilung:\n");
// Prints formatted table showing each language and its count
System.out.println(languageCounts);
Sprachverteilung:
| Sprache | Anzahl |
|------------|--------|
| English | 210 |
| French | 10 |
| Chinese | 6 |
| Portuguese | 1 |
| Spanish | 3 |
| German | 6 |
| Italian | 5 |
// Get numeric column as DoubleColumn type for statistical operations DoubleColumn sales = books.doubleColumn("Sales_in_millions");System.out.println("Verkaufsstatistiken (in Mio. Exemplaren):\n"); // Smallest value in column System.out.println("Min: " + sales.min() + " Mio."); // Largest value in column System.out.println("Max: " + sales.max() + " Mio.");// Average of all values System.out.println("Mittelwert: " + sales.mean() + " Mio."); // Measure of spread (standard deviation) System.out.println("Std.-Abweichung: " + sales.standardDeviation() + " Mio.");
Verkaufsstatistiken (in Mio. Exemplaren):
Min: 10.0 Mio.
Max: 600.0 Mio.
Mittelwert: 49.996875 Mio.
Std.-Abweichung: 64.6846320839116 Mio.
System.out.printf("Zeilen: %d, Spalten: %s", books.rowCount(), books.columnCount());
for (String colName : books.columnNames()) // For each column
System.out.println(books.column(colName).countMissing()); // Count null values
StringColumn language = books.stringColumn("Language"); // Get text column
Table langCounts = books.countBy("Language"); // Count categories
// Calculate numeric statistics
DoubleColumn sales = books.doubleColumn("Sales_in_Millions"); // Get number column
System.out.printf("Mittelwert: %.1f Mio., Min: %.1f Mio., Max: %.1f Mio.",
sales.mean(), sales.min(), sales.max());
Zeilen: 290, Spalten: 6
Books fehlende Werte: 0
Authors fehlende Werte: 0
| Sprache | Anzahl |
|------------|--------|
| English | 210 |
| French | 10 |
Mittelwert: 50.0 Mio., Min: 10.0 Mio., Max: 600.0 Mio.
Datenbereinigung in Java