Chapter 7 Aggregate Methods

import pandas as pd
import numpy as np
url = 'https://github.com/mattharrison/datasets/raw/master/data/vehicles.csv.zip'

df = pd.read_csv(url, usecols = ['city08'])
city_mpg = df.city08

Exercise 1

Find the count of non-missing values of a series.

city_mpg.count()
41144

Exercise 2

Find the number of entries of a series.

city_mpg.size
41144

Exercise 3

Find the number of unique entries of a series

city_mpg.nunique()
105
city_mpg.nunique(dropna=True)
105

Exercise 4

Find the mean value of a series

city_mpg.mean()
18.369045304297103

Exercise 5

Find the maximum value of a series.

city_mpg.max()
150

Exercise 6

Use the .agg method to find all of the above.

city_mpg.agg(['count', 'size', 'nunique', 'mean', 'max'])
count      41144.000000
size       41144.000000
nunique      105.000000
mean          18.369045
max          150.000000
Name: city08, dtype: float64