Skip to content

Instantly share code, notes, and snippets.

@1ambda
Created December 21, 2021 15:26
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/884885502a1e36043139ff83089cd6e3 to your computer and use it in GitHub Desktop.
Save 1ambda/884885502a1e36043139ff83089cd6e3 to your computer and use it in GitHub Desktop.
df\
    .groupBy("brand", "category_code")\
    .agg(countDistinct("product_id").alias("product_count"))\
    .show(truncate=False)
+------------+--------------------------------------+-------------+
|brand |category_code |product_count|
+------------+--------------------------------------+-------------+
|beautix |null |316 |
|dr.gloderm |null |31 |
|farmona |null |39 |
|profhenna |null |56 |
|runail |appliances.environment.vacuum |3 |
|invisibobble|null |2 |
|macadamia |appliances.environment.air_conditioner|1 |
|riche |null |58 |
|nova |null |1 |
|oniq |null |590 |
|lebelage |null |45 |
|fancy |null |15 |
|vilenta |null |20 |
|siberina |null |181 |
|tertio |null |115 |
|jaguar |null |21 |
|nitrimax |apparel.glove |21 |
|jas |null |16 |
|rocknailstar|null |6 |
|koreatida |null |3 |
+------------+--------------------------------------+-------------+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment