This is in relation to the Exploring eBay Car Sales Data guided project.
I am attempting to sort vehicles by price, and display the top 3 entries for each brand of car. My code correctly displays the most expensive cars by brand, but I would like the top 3 entries for each brand.
Any suggestions would be much appreciated! Thank you!
The above code displays the following:
price brand registration_year
36818 350000 porsche 2016
14715 345000 sonstige_autos 2012
47337 259000 bmw 2001
Though I would like it to display the top 3 most expensive cars for porsche, for sonstige, bmw, etc…
I hope will be useful for you.
boolean_brand = auto_clean['brand'] == brand
return auto_clean.loc[boolean_brand,'model'].value_counts()[:5] # top 5
Name: model, dtype: int64
Thanks for the suggestion!
I borrowed your idea and came up with the following, which would work with an iterative loop.
bool = data['brand'] == brand
36818 350000 2016
34723 299000 1977
35923 295000 2015
for i in data['brand'].unique():
I’m glad to see that it has inspired you.