Tablesaw के साथ JSON डेटा बेसिक्स

Java में डेटा इम्पोर्ट करना

Anthony Markham

VP Quant Developer

JSON परिचय

  • JSON: JavaScript Object Notation
    • हल्का डेटा इंटरचेंज फॉर्मेट
    • वेब API का मानक फॉर्मेट
    • की-वैल्यू पेयर संरचना

json_image.jpg

Java में डेटा इम्पोर्ट करना

टेबुलर डेटा

  • फिक्स्ड रो और कॉलम
  • टेबुलर: समान डेटा टाइप्स
| Name  | Age | City    |
|-------|-----|---------|
| Alice | 30  | Boston  |
| Bob   | 25  | Seattle |

JSON

  • लचीली नेस्टेड संरचनाएँ
  • मिले-जुले डेटा टाइप्स और हायरार्की
[
  {"name": "Alice", 
      "age": 30, 
      "address": {"city": "Boston", 
                  "state": "MA"}},
  {"name": "Bob", 
      "age": 25, 
      "address": {"city": "Seattle", 
                  "state": "WA"}}
]
Java में डेटा इम्पोर्ट करना

JSON पढ़ना

  • केवल सरल JSON फाइलों के लिए उपयोग करें
// Simple method to read a JSON file
Table products = Table.read().file("products.json");

$$

import tech.tablesaw.io.json.JsonReader;
import tech.tablesaw.io.json.JsonReadOptions;
  • अतिरिक्त कॉन्फ़िगरेशन उपलब्ध
// Reading a JSON file using JsonReadOptions
JsonReadOptions options = JsonReadOptions.builder("products.json").build();

Table products = new JsonReader().read(options);
Java में डेटा इम्पोर्ट करना

JSON डेटा एक्सेस करना

  • परिचित Tablesaw मेथड काम करते हैं
// Access columns from JSON data
StringColumn names = table.stringColumn("name");
DoubleColumn prices = table.doubleColumn("price");

// Perform calculations double avgPrice = prices.mean(); String mostExpensive = table .where(prices.isEqualTo(prices.max())) .stringColumn("name").get(0);
Java में डेटा इम्पोर्ट करना

सर्वोत्तम JSON प्रैक्टिसेज़ - वैलिडेशन

  • प्रोसेस करने से पहले JSON संरचना वैलिडेट करें
// Validation and error handling
try {
    JsonReadOptions options = JsonReadOptions.builder("data.json").build();
    Table data = new JsonReader().read(options);
    if (data.rowCount() > 0) {
        // Process data
    }
} catch (Exception e) {
    System.err.println("Error reading JSON: " + e.getMessage());
}
if (data.rowCount() == 100) {
    System.out.println("Table has exactly 100 rows - processing data");
}
Java में डेटा इम्पोर्ट करना

सर्वोत्तम JSON प्रैक्टिसेज़ - missing वैल्यूज़

  • missing/null वैल्यू हैंडल करें
// Remove rows with any missing values
data = data.dropRowsWithMissingValues();
  • विश्लेषण के अनुसार डेटा टाइप्स मिलाएँ
// Convert integer column to double for calculations
data = data.replaceColumn("price", data.intColumn("price").asDoubleColumn());
Java में डेटा इम्पोर्ट करना

अभ्यास करते हैं!

Java में डेटा इम्पोर्ट करना

Preparing Video For Download...