JSON परिचय

pandas के साथ सरल Data Ingestion

Amany Mahfouz

Instructor

Javascript Object Notation (JSON)

  • आम वेब डेटा फ़ॉर्मैट
  • टैबुलर नहीं
    • हर रिकॉर्ड में एक जैसे attributes होना ज़रूरी नहीं
  • डेटा objects के collections में व्यवस्थित
  • Objects attribute-value जोड़ों के collections होते हैं
  • Nested JSON: objects के अंदर objects
pandas के साथ सरल Data Ingestion

JSON डेटा पढ़ना

  • read_json()
    • JSON की path string लेता है, या JSON data string के रूप में
    • dtype argument से data types तय करें
    • uncommon JSON layouts के लिए orient argument दें
      • संभावित मान pandas documentation में
pandas के साथ सरल Data Ingestion

Data Orientation

  • JSON डेटा टैबुलर नहीं होता
    • pandas अंदाज़ा लगाकर उसे तालिका में जमाता है
  • pandas आम orientations को अपने-आप संभाल सकता है
pandas के साथ सरल Data Ingestion

Record Orientation

  • सबसे आम JSON arrangement
    [
      {
          "age_adjusted_death_rate": "7.6",
          "death_rate": "6.2",
          "deaths": "32",
          "leading_cause": "Accidents Except Drug Posioning (V01-X39, X43, X45-X59, Y85-Y86)",
          "race_ethnicity": "Asian and Pacific Islander",
          "sex": "F",
          "year": "2007"
      },
      {
          "age_adjusted_death_rate": "8.1",
          "death_rate": "8.3",
          "deaths": "87",
          ...
    
pandas के साथ सरल Data Ingestion

Column Orientation

  • record-oriented JSON से अधिक space-efficient
    {
      "age_adjusted_death_rate": {
          "0": "7.6",
          "1": "8.1",
          "2": "7.1",
          "3": ".",
          "4": ".",
          "5": "7.3",
          "6": "13",
          "7": "20.6",
          "8": "17.4",
          "9": ".",
          "10": ".",
          "11": "19.8",
          ...
    
pandas के साथ सरल Data Ingestion

Orientation बताना

  • Split oriented data - nyc_death_causes.json
    {
      "columns": [
          "age_adjusted_death_rate",
          "death_rate",
          "deaths",
          "leading_cause",
          "race_ethnicity",
          "sex",
          "year"
      ],
      "index": [...],
      "data": [
          [
              "7.6",
    
pandas के साथ सरल Data Ingestion

Orientation बताना

import pandas as pd

death_causes = pd.read_json("nyc_death_causes.json", orient="split")
print(death_causes.head())
  age_adjusted_death_rate death_rate deaths             leading_cause              race_ethnicity sex  year
0                     7.6        6.2     32  Accidents Except Drug...  Asian and Pacific Islander   F  2007
1                     8.1        8.3     87  Accidents Except Drug...          Black Non-Hispanic   F  2007
2                     7.1        6.1     71  Accidents Except Drug...                    Hispanic   F  2007
3                       .          .      .  Accidents Except Drug...          Not Stated/Unknown   F  2007
4                       .          .      .  Accidents Except Drug...       Other Race/ Ethnicity   F  2007

[5 rows x 7 columns]
pandas के साथ सरल Data Ingestion

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

pandas के साथ सरल Data Ingestion

Preparing Video For Download...