PySpark DataFrame का subsetting और cleaning
डेटा की जाँच के बाद, अक्सर डेटा को साफ करना ज़रूरी होता है, जिसमें मुख्यतः subsetting, कॉलम का नाम बदलना, डुप्लिकेट पंक्तियाँ हटाना आदि शामिल होते हैं. PySpark DataFrame API इसके लिए कई ऑपरेटर्स देता है. इस अभ्यास में, आपका काम people_df DataFrame से 'name', 'sex' और 'date of birth' कॉलम का subset बनाना, उस डेटासेट से डुप्लिकेट पंक्तियाँ हटाना, और डुप्लिकेट हटाने से पहले और बाद में पंक्तियों की संख्या गिनना है.
ध्यान रखें, आपके वर्कस्पेस में SparkSession spark और DataFrame people_df पहले से उपलब्ध हैं.
यह अभ्यास पाठ्यक्रम का हिस्सा है
PySpark के साथ Big Data Fundamentals
अभ्यास निर्देश
people_dfसे 'name', 'sex' और 'date of birth' कॉलम select करकेpeople_df_subDataFrame बनाएँ.people_df_subDataFrame में पहली 10 observations प्रिंट करें.people_df_subDataFrame से डुप्लिकेट एंट्री हटाकरpeople_df_sub_nodupDataFrame बनाएँ.- डुप्लिकेट हटाने से पहले और बाद में कुल कितनी पंक्तियाँ हैं?
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Select name, sex and date of birth columns
people_df_sub = people_df.____('name', ____, ____)
# Print the first 10 observations from people_df_sub
people_df_sub.____(____)
# Remove duplicate entries from people_df_sub
people_df_sub_nodup = people_df_sub.____()
# Count the number of rows
print("There were {} rows before removing duplicates, and {} rows after removing duplicates".format(people_df_sub.____(), people_df_sub_nodup.____()))