Simple frequency table using value_counts() method

Let’s take a look at the dataset we’ll work on :

The necessary packages are imported and the dataset is read using the pandas.read_csv() method. df.head() method returns the first 5 rows of the dataset.

Python3




# import packages
import pandas as pd
import numpy as np
  
# reading csv file as pandas dataframe
data = pd.read_csv('iris.csv')
data.head()


Output:

Now let’s find the one-way frequency table of the species column of the dataset.

Python3




df = data['species'].value_counts()
print(df)


Output:

setosa        50
virginica     50
versicolor    50
Name: species, dtype: int64

How to Create Frequency Tables in Python?

In this article, we are going to see how to Create Frequency Tables in Python

Frequency is a count of the number of occurrences a particular value occurs or appears in our data. A frequency table displays a set of values along with the frequency with which they appear. They allow us to better understand which data values are common and which are uncommon. These tables are a great method to arrange your data and communicate the results to others. In this article let’s demonstrate the different ways in which we can create frequency tables in python.

To view and download the CSV file we use in this article click here.

Similar Reads

Method 1: Simple frequency table using value_counts() method

Let’s take a look at the dataset we’ll work on :...

Method 2: One-way frequency table using pandas.crosstab() method

...

Method 3: Two-way frequency table using pandas.crosstab() method

...