0

Some data related to the question:

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 38223 entries, 0 to 38222
Data columns (total 16 columns):
 #   Column            Non-Null Count  Dtype  
---  ------            --------------  -----  
 0   trans_id          38223 non-null  int64  
 1   prod_upc          38223 non-null  int64  
 2   cust_id           38223 non-null  int64  
 3   trans_timestamp   38223 non-null  object 
 4   trans_year        38223 non-null  int64  
 5   trans_month       38223 non-null  int64  
 6   trans_day         38223 non-null  int64  
 7   trans_hour        38223 non-null  int64  
 8   trans_quantity    38223 non-null  int64  
 9   cust_age          38223 non-null  int64  
 10  cust_state        38223 non-null  object 
 11  prod_price        38223 non-null  float64
 12  prod_title        38223 non-null  object 
 13  prod_category     38223 non-null  object 
 14  prod_animal_type  38223 non-null  object 
 15  total_sales       38223 non-null  float64
dtypes: float64(2), int64(9), object(5)
memory usage: 4.7+ MB
prod_title
Reddy Beddy               6583
Yum Fish-Dish             4298
Kitty Climber             3329
Feline Fix Mix            3262
Tuna Tasties              3102
Chewie Dental             2579
Purrfect Puree            2453
Whole Chemistry Recipe    2410
Cat Cave                  2408
Snoozer Hammock           2311
All Veggie Yummies        2296
Chomp-a Plush             2114
Snoozer Essentails        2058
Fetch Blaster             1898
Ball and String           1885
Purr Mix                  1876
Foozy Mouse               1863
Scratchy Post             1833
Snack-em Fish             1585
The New Bone              1234
Tug-a-Back                1152
Name: trans_quantity, dtype: int64
prod_title
Reddy Beddy               408023.09
Cat Cave                  175759.92
Kitty Climber             119810.71
Snoozer Hammock           106282.89
Snoozer Essentails        100739.10
Yum Fish-Dish              81447.10
Scratchy Post              65951.34
Feline Fix Mix             65207.38
Foozy Mouse                61460.37
Tuna Tasties               58782.90
Ball and String            53628.25
Fetch Blaster              47355.10
Purrfect Puree             46484.35
Chomp-a Plush              46402.30
Whole Chemistry Recipe     31257.70
Chewie Dental              28291.63
Tug-a-Back                 26484.48
Snack-em Fish              25344.15
Purr Mix                   24369.24
All Veggie Yummies         22845.20
The New Bone               13561.66
Name: total_sales, dtype: float64

Question 1: What are the top ten product titles by the total number of items sold for that product? Display in descending order. Store in variable top_num_sales.

Question 2: What are the top ten product titles by total dollar amount made? Display in descending order. Store in variable top_tot_sales.

Answer for Q 1:
Code: "product_sales = df.groupby('prod_title')\['trans_quantity'\].sum()

top_num_sales = product_sales.sort_values(ascending=False)\[:10\].index.tolist()"

Output:

Your answer for the `top_tot_sales` isn't quite right.Looks like you have 1 or more products that aren't correct. You might want to check the order of your answer.
Take a closer look at your code to see what you can change.

Answer for Q 2:

Code: "

df_cleaned\['total_sales'\] = df_cleaned\['trans_quantity'\] \* df_cleaned\['prod_price'\]
    
top_tot_sales = df_cleaned.groupby('prod_title')\['total_sales'\].sum().sort_values(ascending=False).head(10)

print(top_tot_sales)`

Output:

Your answer for the `top_tot_sales` isn't quite right.Looks like you have 1 or more products that aren't correct. You might want to check the order of your answer.
Take a closer look at your code to see what you can change.
Elkhan
  • 360
  • 2
  • 15
  • Did you check your output, and did you tried to do manually, just to check you are not doing a dumb error? – Giacomo Catenazzi Apr 17 '23 at 09:12
  • No, I checked the scrubbed data and everything seems okay to me or else they wouldn't let me do these questions, I had to pass the scrubbing test too. So I think the error is in the coding only... – Nehal Paul Apr 17 '23 at 12:26
  • Would you kindly help, please? If you can find any error in the given data... that would go a long way. Thank you so much for your advice. – Nehal Paul Apr 17 '23 at 12:28

0 Answers0