Video quiz

There is just one video quiz this week, but it is a little more difficult than usual; it is meant as practice for the midterm.

Here is the documentation for the pandas method pd.to_datetime. Notice that one of the allowable inputs is a pandas Series.

Here we try the pd.to_datetime function using a list as our input instead of a Series.

import pandas as pd

x = pd.to_datetime(["9/30/2021","10/7/2021","10/14/2021","10/21/2021"])
x
DatetimeIndex(['2021-09-30', '2021-10-07', '2021-10-14', '2021-10-21'], dtype='datetime64[ns]', freq=None)
len(x)
4
type(x[0])
pandas._libs.tslibs.timestamps.Timestamp
x[0].day_name()
'Thursday'
x[1].month_name()
'October'

Practice Exercise

  1. Import our usual Spotify dataset using the option na_values=" " to tell pd.read_csv that the blank spaces represent NaN values.

  2. Convert the “Release Date” column so that it has datetime as its data type.

  3. How many songs in our dataset were released on a Tuesday?

Video solution

Notebook from the video

Canvas video quiz

Link to the Canvas quiz

Due Monday before lecture.