Exercise

Dates (II)

Instead of converting the type of a column after importing the data, you can import the data while parsing the dates correctly. To do this, you can pass the parse_dates argument of pd.read_csv() a list of column names that should be imported as dates. Once the date column is imported as the correct type (datetime64), you can make use of the .dt accessor along with the .year, .month, and .day attributes to can access the year, month, and day from these dates.

# Access year
df['Date'].dt.year

# Access month
df['Date'].dt.month

# Access day
df['Date'].dt.day

Instructions 1/2

undefined XP
    1
    2

Import the dataset and ensure that the 'Date' column is imported as datetime type. After importing, inspect the type of 'Date' column.