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.
Este ejercicio forma parte del curso
Streamlined Data Ingestion with pandas
Instrucciones del ejercicio
- 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.
Ejercicio interactivo práctico
Prueba este ejercicio y completa el código de muestra.
# 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())