Java'da Veri İçe Aktarma
Anthony Markham
VP Quant Developer

| İsim | Yaş | Şehir |
|-------|-----|---------|
| Alice | 30 | Boston |
| Bob | 25 | Seattle |
[
{"name": "Alice",
"age": 30,
"address": {"city": "Boston",
"state": "MA"}},
{"name": "Bob",
"age": 25,
"address": {"city": "Seattle",
"state": "WA"}}
]
// Basit bir JSON dosyasını okuma yöntemi
Table products = Table.read().file("products.json");
$$
import tech.tablesaw.io.json.JsonReader;
import tech.tablesaw.io.json.JsonReadOptions;
// JsonReadOptions kullanarak bir JSON dosyası okuma JsonReadOptions options = JsonReadOptions.builder("products.json").build();Table products = new JsonReader().read(options);
Tablesaw yöntemleri çalışır// JSON verilerinden sütunlara erişim StringColumn names = table.stringColumn("name"); DoubleColumn prices = table.doubleColumn("price");// Hesaplamalar yapın double avgPrice = prices.mean(); String mostExpensive = table .where(prices.isEqualTo(prices.max())) .stringColumn("name").get(0);
// Doğrulama ve hata yönetimi
try {
JsonReadOptions options = JsonReadOptions.builder("data.json").build();
Table data = new JsonReader().read(options);
if (data.rowCount() > 0) {
// Veriyi işleyin
}
} catch (Exception e) {
System.err.println("JSON okuma hatası: " + e.getMessage());
}
if (data.rowCount() == 100) {
System.out.println("Tablo tam olarak 100 satır içeriyor - veri işleniyor");
}
// Eksik değer içeren satırları kaldır
data = data.dropRowsWithMissingValues();
// Hesaplamalar için tamsayı sütununu double'a dönüştür
data = data.replaceColumn("price", data.intColumn("price").asDoubleColumn());
Java'da Veri İçe Aktarma