Session Ready
Exercise

Cleaning and tidying datetime data

In order to use the full power of pandas time series, you must construct a DatetimeIndex. To do so, it is necessary to clean and transform the date and time columns.

The DataFrame df_dropped you created in the last exercise is provided for you and pandas has been imported as pd.

Your job is to clean up the date and Time columns and combine them into a datetime collection to be used as the Index.

Instructions
100 XP
  • Convert the 'date' column to a string with .astype(str) and assign to df_dropped['date'].
  • Add leading zeros to the 'Time' column. This has been done for you.
  • Concatenate the new 'date' and 'Time' columns together. Assign to date_string.
  • Convert the date_string Series to datetime values with pd.to_datetime(). Specify the format parameter.
  • Set the index of the df_dropped DataFrame to be date_times. Assign the result to df_clean.