0

The question I'm trying to solve is to find the products with the slowest shipping speed.

the first step I did was to find the mean shipping speed for the products using the following code

westData.groupby('Product ID')['Shipping Speed'].agg(lambda x: x.mean())

and the result I have is in the following format

mean shipping speed per product

now I'm trying to filter the results to get only the results with the slowest shipping speed. in other words, return only the values that equal the maximum mean from the shipping speed column.

in my case the slowest shipping speed is

westData.groupby('Product ID')['Shipping Speed'].agg(lambda x: x.mean()).max()

Timedelta('7 days 00:00:00')

So I need to return only the products with the shipping speed of ('7 days 00:00:00')

which should be like the following

required output

Anas Baheh
  • 137
  • 2
  • 13
  • Pls explain better what are you after. What does the code you posted output? – gtomer Sep 08 '20 at 18:46
  • have you read [this](https://stackoverflow.com/questions/31581537/after-groupby-and-sum-how-to-get-the-max-value-rows-in-pandas-dataframe/31581568) or [this](https://stackoverflow.com/questions/15705630/get-the-rows-which-have-the-max-count-in-groups-using-groupby)? – felipsmartins Sep 08 '20 at 18:49

1 Answers1

1

After you get the mean

s = westData.groupby('Product ID')['Shipping Speed'].mean()

Filter with max

s = s[s==s.max()]
items = s.index.tolist()
BENY
  • 317,841
  • 20
  • 164
  • 234