टेक्स्ट कॉलम को split और explode करें
एक डेटाफ़्रेम clauses_df दिया गया है जिसमें 100 पंक्तियाँ हैं। इसमें clause नाम का एक कॉलम और एक row id है। प्रत्येक clause एक स्ट्रिंग है जिसमें एक या अधिक शब्द हैं जो स्पेस से अलग किए गए हैं.
यह अभ्यास पाठ्यक्रम का हिस्सा है
Python में Spark SQL परिचय
अभ्यास निर्देश
clauseकॉलम कोwordsनाम के कॉलम में split कीजिए, जिसमें अलग-अलग शब्दों की एक array हो।wordsकॉलम को explode करकेwordनाम का कॉलम बनाइए।- प्राप्त पंक्तियों की संख्या गिनिए.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Split the clause column into a column called words
split_df = clauses_df.select(____('clause', ' ').____('words'))
split_df.show(5, truncate=False)
# Explode the words column into a column called word
exploded_df = split_df.____(____('____').____('word'))
exploded_df.show(10)
# Count the resulting number of rows in exploded_df
print("\nNumber of rows: ", ____)