cancel
Showing results for 
Search instead for 
Did you mean: 
Community Discussions
Connect with fellow community members to discuss general topics related to the Databricks platform, industry trends, and best practices. Share experiences, ask questions, and foster collaboration within the community.
cancel
Showing results for 
Search instead for 
Did you mean: 

Plot number of abandoned cart items by product

SSV_dataeng
New Contributor II
abandoned_carts_df = (email_carts_df.filter(col('converted') == False).filter(col('cart').isNotNull()))
display(abandoned_carts_df)
 SSV_dataeng_0-1690194232666.png
abandoned_items_df = (abandoned_carts_df.select(col("cart").alias("items")).groupBy("items").count())
display(abandoned_items_df)

verfiication Failed

expected_columns = ["items", "count"]
expected_count = 12
assert abandoned_items_df.count() == expected_count, "Counts do not match"
assert abandoned_items_df.columns == expected_columns, "Columns do not match"
print("All test pass")
 
AssertionError: Counts do not match
--------------------------------------------------------------------------- AssertionError Traceback (most recent call last) <command-1787238488083704> in <cell line: 5>() 3 expected_count = 12 4 ----> 5 assert abandoned_items_df.count() == expected_count, "Counts do not match" 6 7 assert abandoned_items_df.columns == expected_columns, "Columns do not match" AssertionError: Counts do not match
2 REPLIES 2

daniel_sahal
Esteemed Contributor

@SSV_dataeng 
What is the question here?

NandiniN
Honored Contributor
Honored Contributor

Hi @SSV_dataeng ,

Try 

abandoned_items_df = (abandoned_carts_df
.withColumn("items", explode("cart"))
.groupBy("items")
.count()
.sort("items")
)

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!