Skip to content
Data Manipulation with pandas
Run the hidden code cell below to import the data used in this course.
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
Explore Datasets
Use the DataFrames imported in the first cell to explore the data and practice your skills!
- Print the highest weekly sales for each
department
in thewalmart
DataFrame. Limit your results to the top five departments, in descending order. If you're stuck, try reviewing this video. - What was the total
nb_sold
of organic avocados in 2017 in theavocado
DataFrame? If you're stuck, try reviewing this video. - Create a bar plot of the total number of homeless people by region in the
homelessness
DataFrame. Order the bars in descending order. Bonus: create a horizontal bar chart. If you're stuck, try reviewing this video. - Create a line plot with two lines representing the temperatures in Toronto and Rome. Make sure to properly label your plot. Bonus: add a legend for the two lines. If you're stuck, try reviewing this video.
pivot_table()
# Pivot for mean weekly_sales by store type and holiday
mean_sales_by_type_holiday = sales.pivot_table(values = 'weekly_sales', index = 'type', columns= 'is_holiday')
# Print mean_sales_by_type_holiday
print(mean_sales_by_type_holiday)
Hidden output
Output:
is_holiday False True
type
A 23768.584 590.045
B 25751.981 810.705
Hidden output
Removing 'columns' and passing 'type' and 'is_holiday' as list values to 'index'
mean_sales_by_type_holiday = sales.pivot_table(values = 'weekly_sales', index = ['type', 'is_holiday'])
Output:
weekly_sales
type is_holiday
A False 23768.584
True 590.045
B False 25751.981
True 810.705