Chapter 5 Series Deep Dive

Chapter 5 Series Deep Dive

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

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

city_mpg = df.city08
city_mpg
0        19
1         9
2        23
3        10
4        17
         ..
41139    19
41140    20
41141    18
41142    18
41143    16
Name: city08, Length: 41144, dtype: int64

Exercise 1

Explore the documentation for five attributes of a series from Jupyter

This produces a rather lengthy bit of output. As such, I’ve truncated it here.

dir(city_mpg)[:20]
['T',
 '_AXIS_LEN',
 '_AXIS_ORDERS',
 '_AXIS_REVERSED',
 '_AXIS_TO_AXIS_NUMBER',
 '_HANDLED_TYPES',
 '__abs__',
 '__add__',
 '__and__',
 '__annotations__',
 '__array__',
 '__array_priority__',
 '__array_ufunc__',
 '__array_wrap__',
 '__bool__',
 '__class__',
 '__contains__',
 '__copy__',
 '__deepcopy__',
 '__delattr__']

I chose somewhat arbitrarily to look at:

Exercise 2

How many attributes are found on the .str attribute? Look at the documentation for three of them.

s_str = pd.Series(['a','b','c'])

n_attributes = len(dir(s_str.str))

print('There are {} attributes foiund on the .str attribute'.format(n_attributes))
There are 97 attributes foiund on the .str attribute

I chose somewhat arbitrarily to review the following:

Exercise 3

How many attributes are found on the .dt attribute? Look at the documentation for three of them.

s_ts = pd.to_datetime(pd.Series(['2022-01-01','2022-01-02','2022-01-03']))

n_attributes = len(dir(s_ts.dt))

print('There are {} attributes foiund on the .dt attribute'.format(n_attributes))
There are 83 attributes foiund on the .dt attribute

Once more, I chose somewhat arbitrarily to review the following: