Checking the quartiles of a dataset
The quartile is like the percentile because it can be used to measure the spread and identify the center of a dataset. Percentiles and quartiles are called quantiles. While the percentile divides the dataset into 100 equal portions, the quartile divides the dataset into 4 equal portions. Typically, three quartiles will split your dataset into four equal portions.
To analyze the quartiles of a dataset, we will use the quantiles
method from the numpy
library in Python. Unlike percentile
, the quartile doesn’t have a specific method dedicated to it.
Getting ready
We will work with the COVID-19 cases again for this recipe.
How to do it…
We will compute the quartiles using the numpy
library:
- Import the
numpy
andpandas
libraries:import numpy as np import pandas as pd
- Load the
.csv
into a dataframe usingread_csv
. Then subset the dataframe to include only relevant columns:covid_data = pd.read_csv("covid-data...