Operations को chain करना
अब जब आप डेटा लोड और clean कर चुके हैं, तो आप उसका विश्लेषण शुरू कर सकते हैं. आपका पहला काम राजनेताओं की जन्म-तिथियों को देखना है. जन्म-तिथियाँ 'YYYY-MM-DD' जैसी string फॉर्मेट में हैं. string के पहले 4 characters वर्ष (year) होते हैं.
पिछले अभ्यास में आपने जो filtered Dask bag बनाया था, filtered_bag, वह आपके environment में उपलब्ध है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Dask के साथ Parallel Programming
अभ्यास निर्देश
- bag के
.pluck()मेथड का उपयोग करके'birth_date'strings निकालें. - एक lambda फंक्शन लिखें जो
'birth_date'strings से year वाली string निकाले और उसे integer में बदले. - नए bag
birth_year_bagका उपयोग करके min, max, और mean birth years निकालें. - इन तीनों aggregates को कुशलतापूर्वक निकालने के लिए
dask.compute()फंक्शन का उपयोग करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Select the 'birth_date' from each dictionary in the bag
birth_date_bag = filtered_bag.____
# Extract the year as an integer from the birth_date strings
birth_year_bag = birth_date_bag.____(lambda x: ____)
# Calculate the min, max and mean birth years
min_year = ____
max_year = ____
mean_year = ____
# Compute the results efficiently and print them
print(____(____))