Generating the range of a dataset
The range also helps us understand the spread of a dataset or how far apart the dataset’s numbers are from each other. It is the difference between the minimum and maximum values within a dataset. It is a very useful statistic, especially when used alongside the variance and standard deviation of a dataset.
To analyze the range of a dataset, we will use the max
and min
methods from the numpy
library in Python.
Getting ready
We will work with the COVID-19 cases again for this recipe.
How to do it…
We will compute the range 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.csv") covid_data = covid_data[['iso_code','continent','location','date','total_cases',...