chevron_left
Miscellaneous Cookbook
Adjusting number of rows that are printedAppending DataFrame to an existing CSV fileChecking differences between two indexesChecking if a DataFrame is emptyChecking if a variable is a DataFrameChecking if index is sortedChecking if value exists in IndexChecking memory usage of DataFrameChecking whether a Pandas object is a view or a copyConcatenating a list of DataFramesConverting a DataFrame to a listConverting a DataFrame to a SeriesConverting DataFrame to a list of dictionariesConverting DataFrame to list of tuplesCounting the number of negative valuesCreating a DataFrame using cartesian product of two DataFramesDisplaying DataFrames side by sideDisplaying full non-truncated DataFrame valuesDrawing frequency histogram of DataFrame columnHighlighting a particular cell of a DataFrameHighlighting DataFrame cell based on valueHow to solve "ValueError: If using all scalar values, you must pass an index"Plotting two columns of DataFramePrinting DataFrame on a single linePrinting DataFrame without indexPrinting DataFrames in tabular formatRandomly splitting DataFrame into multiple DataFrames of equal sizeReducing DataFrame memory sizeSaving a DataFrame as a CSV fileSaving DataFrame as Excel fileSaving DataFrame as feather fileSetting all values to zeroShowing all dtypes without truncationSplitting DataFrame into multiple DataFrames based on valueSplitting DataFrame into smaller equal-sized DataFramesWriting DataFrame to SQLite
0
0
0
new
Drawing frequency histogram of Pandas DataFrame column
Programming
chevron_rightPython
chevron_rightPandas
chevron_rightCookbooks
chevron_rightDataFrame Cookbooks
chevron_rightMiscellaneous Cookbook
schedule Mar 10, 2022
Last updated Python●Pandas
Tags tocTable of Contents
expand_more Consider the following DataFrame:
import pandas as pd
'class':['A','A','B','A','B','C'], 'name':['alex','bob','cathy','doge','eric','fred']})df
class name0 A alex1 A bob2 B icathy3 A doge4 B eric5 C fred
Using matplotlib
To draw a frequency histogram of the class
column:
import matplotlib.pyplot as plt
plt.hist(df['class'])plt.ylabel('Frequency count')plt.xlabel('Data');plt.title('My histogram')plt.show()
This gives you the following plot:

Using seaborn
The other alternative is to use the seaborn
library:
import seaborn as snssns.countplot(x=df['class'])
We get the following:

Published by Isshin Inada
Edited by 0 others
Did you find this page useful?
Ask a question or leave a feedback...