Extracting datetime components
There are several columns in the volunteer dataset comprised of datetimes. Let's take a look at the start_date_date column and extract just the month to use as a feature for modeling.
Diese Übung ist Teil des Kurses
Preprocessing for Machine Learning in Python
Anleitung zur Übung
- Convert the
start_date_datecolumn into apandasdatetime column and store it in a new column calledstart_date_converted. - Retrieve the month component of
start_date_convertedand store it in a new column calledstart_date_month. - Print the
.head()of just thestart_date_convertedandstart_date_monthcolumns.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# First, convert string column to date column
volunteer["start_date_converted"] = pd.____(____)
# Extract just the month from the converted column
volunteer["start_date_month"] = volunteer[____].____
# Take a look at the converted and new month columns
print(volunteer[[____, ____]].____)