Skip to content

Instantly share code, notes, and snippets.

@1ambda
Created December 20, 2021 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1ambda/1ecd1d324316d010b5405834943c350a to your computer and use it in GitHub Desktop.
Save 1ambda/1ecd1d324316d010b5405834943c350a to your computer and use it in GitHub Desktop.
dfConverted1 = dfSelected\
withColumn("count_children", coalesce("count_kid", lit(0)) + coalesce("count_teen", lit(0)))
dfConverted1\
.select(col("id"), col("count_kid"), col("count_teen"), col("count_children"))\
.limit(5)\
.show()
# `show() 출력 결과
+----+---------+----------+--------------+
| id|count_kid|count_teen|count_children|
+----+---------+----------+--------------+
|5524| 0| 0| 0|
|2174| 1| 1| 2|
|4141| 0| 0| 0|
|6182| 1| 0| 1|
|5324| 1| 0| 1|
+----+---------+----------+--------------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment