शुरू करेंमुफ़्त में शुरू करें

Array कॉलम का अभ्यास

SQL फंक्शन udf उपलब्ध है, साथ ही एक dataframe df_before भी उपलब्ध है, जिसका टाइप DataFrame[doc: array<string>, in: array<string>, out: array<string>] है.

TRIVIAL_TOKENS वैरिएबल एक set है। इसमें वे कुछ शब्द हैं जिन्हें हम हटाना चाहते हैं.

यह अभ्यास पाठ्यक्रम का हिस्सा है

Python में Spark SQL परिचय

पाठ्यक्रम देखें

अभ्यास निर्देश

  • df_before की वे rows दिखाएँ जिनमें doc में item 5 शामिल है.
  • ऐसा udf बनाएँ जो array कॉलम से TRIVIAL_TOKENS में मौजूद items हटा दे। ऑर्डर को बनाए रखना ज़रूरी नहीं है.
  • df2 की in और out कॉलम से वे tokens हटा दें जो TRIVIAL_TOKENS में आते हैं.

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

# Show the rows where doc contains the item '5'
df_before.where(array_contains('doc', '____')).show()

# UDF removes items in TRIVIAL_TOKENS from array
rm_trivial_udf = udf(lambda x:
                     list(set(x) - ____) if x
                     else x,
                     ArrayType(____()))

# Remove trivial tokens from 'in' and 'out' columns of df2
df_after = df_before.withColumn('in', ____('in'))\
                    .withColumn('out', ____('out'))

# Show the rows of df_after where doc contains the item '5'
df_after.where(array_contains('doc','5')).show()
कोड संपादित करें और चलाएँ