cancel
Showing results for 
Search instead for 
Did you mean: 
Community Platform 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
Databricks Employee
Databricks Employee

Hi @SSV_dataeng ,

Try 

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

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group