Bar Plot

Learn how to create bar plots comparing categorical features to sales.

Chapter Goals:

  • Create a bar plot to visualize the correlation between dataset features and weekly sales

A. Categorical feature plots

For categorical features, it doesn’t make sense to create a scatter plot. Instead, when we’re using a categorical feature as the independent variable (with a numeric feature as the dependent variable), we’ll make a bar plot.

When using weekly sales as the dependent variable, we’ll create bar plots that show the average weekly sale amount for each category in a categorical feature.

Press + to interact
plot_df = final_dataset[['Weekly_Sales', 'Type']]
plot_df = plot_df.groupby('Type').mean()
plot_df.plot.bar()
plt.title('Store Type vs. Weekly Sales')
plt.xlabel('Type')
plt.ylabel('Avg Weekly Sales (Dollars)')
plt.show()

The above bar plot shows that stores of type A have significantly higher average weekly sales than stores of type B or C.

Get hands-on with 1300+ tech skills courses.