Skip to content
1 hidden cell
Data Manipulation with pandas
Data Manipulation with pandas
Run the hidden code cell below to import the data used in this course.
1 hidden cell
Take Notes
Add notes about the concepts you've learned and code cells with code you want to keep.
Add your notes here
# Add your code snippets here
To print the highest weekly sales for each department in the walmart
DataFrame, we can group the data by department and then find the maximum weekly sales for each department. We can then sort the results in descending order and limit the output to the top five departments.
Here's the code to achieve this:
# Group the data by department and find the maximum weekly sales for each department max_sales = walmart.groupby('department')['weekly_sales'].max() # Sort the results in descending order and limit the output to the top five departments top_five = max_sales.sort_values(ascending=False).head(5) # Print the results print(top_five)