# P4.5 List of Dictionaries: Table data Python मध्ये कसा दिसतो?

Source: https://ravindrabagale.com/mr/datascience/py04-python-lists-tuples-dictionaries-and-sets-with-examples/p4-5-list-of-dictionaries-how-table-data-looks-in.html
Language: mr (Marathi with English technical terms)

हे का शिकायचं?

CSV, JSON, database — सगळीकडे data rows मध्ये येतो. Python मध्ये तो list of dictionaries असतो आणि pandas चा पायाही हाच.

हे काय आहे?

प्रत्येक dictionary म्हणजे एक row आणि keys म्हणजे columns. Loop ने rows वर काम करता येतं.

कसं करायचं?

Step 1. प्रत्येक row ची dictionary बनवा.
Step 2. सगळ्या rows एका list मध्ये ठेवा.
Step 3. Loop ने filter किंवा total करा.

उदाहरण A: Table तयार करा

```python
orders = [
    {"order_id": "O1", "city": "Pune", "amount": 450},
    {"order_id": "O2", "city": "Mumbai", "amount": 1200},
    {"order_id": "O3", "city": "Pune", "amount": 300},
]
print(len(orders))
print(orders[1]["city"])
```

Output:

```text
3
Mumbai
```

याचा अर्थ: प्रत्येक dictionary एक row आहे.

उदाहरण B: एका city चा total

```python
orders = [
    {"order_id": "O1", "city": "Pune", "amount": 450},
    {"order_id": "O2", "city": "Mumbai", "amount": 1200},
    {"order_id": "O3", "city": "Pune", "amount": 300},
]
pune_total = sum(o["amount"] for o in orders if o["city"] == "Pune")
print(pune_total)
```

Output:

```text
750
```

याचा अर्थ: Loop ने फक्त त्या city च्या rows ची बेरीज केली. pandas हेच एका line मध्ये करतो.

रवींद्र बागले यांची tip

तुमचा data list of dictionaries म्हणून लिहिता आला तर `pd.DataFrame(orders)` ने तो pandas मध्ये load होतो.
