मिसिंग कॉलम जोड़ना
एक साल की एक्सट्रैक्टेड फ़ाइल में pub कॉलम (publisher) गायब है, लेकिन टीम दोनों फ़ाइलों को एक ही डेटासेट की तरह स्कैन करना चाहती है. सही आर्ग्युमेंट चुनिए ताकि Polars फेल होने की बजाय जहाँ कॉलम मिसिंग हो वहाँ null डाल दे.
polars pl के रूप में लोड है, और डायरेक्टरी DRIFT_DIR में है. हर फ़ाइल का हेडर आपके लिए प्रिंट किया गया है ताकि आप स्कीमा का अंतर देख सकें.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Polars के साथ Data Pipelines का स्केलिंग और ऑप्टिमाइज़ेशन
अभ्यास निर्देश
DRIFT_DIRमें हरseattle_*.csvफ़ाइल को स्कैन करने के लिए एक glob pattern का उपयोग करें.- सही आर्ग्युमेंट जोड़ें ताकि कुछ फ़ाइलों में मिसिंग कॉलम के लिए Polars nulls इंसर्ट कर दे.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Scan both yearly files as one combined dataset
combined = pl.scan_csv(
str(DRIFT_DIR / "____"),
try_parse_dates=True,
# Insert missing columns instead of failing on schema differences
____="____",
)
result = combined.select("date", "format", "title", "pub").collect()
print("First rows (from 2023 file):")
print(result.head(3))
print("\nLast rows (from 2024 file):")
print(result.tail(3))