Code python

PySpark split and explode example

Kontext Kontext visibility 56 comment 0 access_time 2 months ago language English

descriptionCode description

This code snippet shows you how to define a function to split a string column to an array of strings using Python built-in split function. It then explodes the array element from the split into using PySpark built-in explode function.


Sample output

+----------+-----------------+--------------------+-----+
|  category|            users|         users_array| user|
+----------+-----------------+--------------------+-----+
|Category A|user1,user2,user3|[user1, user2, us...|user1|
|Category A|user1,user2,user3|[user1, user2, us...|user2|
|Category A|user1,user2,user3|[user1, user2, us...|user3|
|Category B|      user3,user4|      [user3, user4]|user3|
|Category B|      user3,user4|      [user3, user4]|user4|
+----------+-----------------+--------------------+-----+
fork_rightFork
more_vert
info Last modified by Administrator 2 months ago copyright This page is subject to Site terms.
comment Comments
No comments yet.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts