The 6 AI Engineering Patterns, come build with Greg live:Β Starts Jan 6th, 2025
Leverage
Pandas functions

Pandas Bar Plot – DataFrame.plot.bar()

Create bar plot from DataFrame in pandas

Pandas Bar Plot is a great way to visually compare 2 or more items together. Traditionally, bar plots use the y-axis to show how values compare to each other.

In order to make a bar plot from your DataFrame, you need to pass a X-value and a Y-value. Pandas will draw a chart for you automatically.

pandas.DataFrame.plot.bar(x=your_x_values, y=your_y_values)

Pseudo Code: Construct a bar plot from a column(s) and index within a DataFrame.

Pandas Bar Plot

Resample Main Parameters

  • x – What you want to have your bars be. This is traditionally a label (cat, dog, mouse).
  • y – What you want the values or height of your bar plot to be. This is almost always a number (3, 4, 5, 6, etc.)
  • color – The color you want your bars to be. If you have multiple sets of bars (like in a grouped or stacked bar plot) you can pass multiple colors via a list or dict.
  • **kwargs – Pandas plot has a ton of general parameters you can pass. These are all agnostic to the type of plot you do.

Now the fun part, let’s take a look at a code sample

Link to code

Official Documentation

On this page