0

I'm working with the Northwind database (download link, documentation).

I wanted to check the popularity of sold products, I did it in the following way

order_details_products = order_details.merge(products, on = 'productID') order_details_products_categories = order_details_products.merge(categories, on = 'categoryID') popularity_products = order_details_products_categories.groupby(['productID', 'categoryID', 'categoryName']).agg(no_orders = ('productID', 'count')) popularity_products.sort_values(by = 'no_orders', ascending = False, inplace = True) 

It works and it perfectly returns what I need. However there's an issue I don't know how to deal with. When I check the shape of my dataframe popularity_products I get the following output

popularity_products.shape Out[27]: (77, 1) 

That means that my dataframe contains only one column: no_orders. Is it possible to make a dataframe with 4 columns: productID, categoryID, categoryName?

Regards.

1
  • 1
    just add reset_index or .to_frame to the end Commented May 9, 2020 at 11:44

1 Answer 1

1

Should be possible to use:

popularity_products = popularity_products.to_frame().reset_index() 
Sign up to request clarification or add additional context in comments.

2 Comments

There's no attribute to_frame according to Spyder.
In that case try just popularity_products = popularity_products.reset_index()

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.