Python | Pandas Dataframe.plot.bar

Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.

Pandas DataFrame.plot.bar() plots the graph vertically in form of rectangular bars.

Syntax : DataFrame.plot.bar(x=None, y=None, **kwds)

Parameters:
x : (label or position, optional) Allows plotting of one column versus another. If not specified, the index of the DataFrame is used.
y : (label or position, optional) Allows plotting of one column versus another. If not specified, all numerical columns are used.
**kwds : Additional keyword arguments

Returns: matplotlib.axes.Axes or np.ndarray of them

Example #1: Using DataFrame.plot.bar() to plot the graph vertically in form of rectangular bars

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing matplotlib
import matplotlib.pyplot
  
# importing pandas as pd
import pandas as pd
  
# importing numpy as np
import numpy as np
  
# creating a dataframe 
df = pd.DataFrame(np.random.rand(10, 3), columns =['a', 'b', 'c'])
  
print(df)

chevron_right



Now we will use a function DataFrame.plot.bar() to plot a graph vertically in form of rectangular bars

filter_none

edit
close

play_arrow

link
brightness_4
code

# using a function df.plot.bar()
df.plot.bar()

chevron_right


Output:
plot.bar1()
 
Example #2: Using DataFrame.plot.bar() to plot the graph vertically in form of rectangular bars.

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing matplotlib
import matplotlib.pyplot
  
# importing pandas as pd
import pandas as pd
  
# importing numpy as np
import numpy as np
  
# creating a dataframe
df = pd.DataFrame(np.random.rand(10, 10),
                  columns =['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'])
  
df

chevron_right



Now we will use a function DataFrame.plot.bar() to plot a graph vertically in form of rectangular bars

filter_none

edit
close

play_arrow

link
brightness_4
code

# using a function df.plot.bar()
df.plot.bar()

chevron_right


Output :



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.