Skip to content

Instantly share code, notes, and snippets.

@1ambda
Created December 27, 2021 12:32
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/ff840accd6a947f18c90d991537ec339 to your computer and use it in GitHub Desktop.
Save 1ambda/ff840accd6a947f18c90d991537ec339 to your computer and use it in GitHub Desktop.
dfListingReviewStat = dfListingReview\
.groupBy(col("listing_id"))\
.agg(count("*").alias("count_review"))
dfListingReview = dfListingMeta\
.select(
col("id").alias("listing_id"),
col("name").alias("listing_name"))\
.alias("LISTING_META")\
.join(
other = dfListingReviewStat.alias("LISTING_REVIEW"),
on = col("LISTING_META.listing_id") == col("LISTING_REVIEW.listing_id"),
how = "inner"
)\
.select(
col("LISTING_META.listing_id"),
col("LISTING_META.listing_name"),
coalesce(col("LISTING_REVIEW.count_review"), lit(0)).alias("count_review")
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment