Get datetimes from multiple columns
Sometimes, datetime data is split across columns. A dataset might have a date and a time column, or a date may be split into year, month, and day columns.
A column in this version of the survey data has been split so that dates are in one column, Part2StartDate, and times are in another, Part2StartTime. Your task is to use read_excel()'s parse_dates argument to combine them into one datetime column with a new name.
pandas has been imported as pd.
Cet exercice fait partie du cours
Streamlined Data Ingestion with pandas
Instructions
- Create a dictionary,
datetime_colsindicating that the new columnPart2Startshould consist ofPart2StartDateandPart2StartTime. - Load the survey response file, supplying the dictionary to the
parse_datesargument to create a newPart2Startcolumn. - View summary statistics about the new
Part2Startcolumn with thedescribe()method.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
# Create dict of columns to combine into new datetime column
datetime_cols = {"Part2Start": ____}
# Load file, supplying the dict to parse_dates
survey_data = pd.read_excel("fcc_survey_dts.xlsx",
____)
# View summary statistics about Part2Start
print(survey_data.Part2Start.describe())