0
0
Pandasdata~10 mins

to_datetime() for date parsing in Pandas - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to convert the 'date' column to datetime format.

Pandas
df['date'] = pd.[1](df['date'])
Drag options to blanks, or click blank then click option'
Adatetime_parse
Bto_date
Cconvert_date
Dto_datetime
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent function like to_date or convert_date.
Trying to convert without using pandas functions.
2fill in blank
medium

Complete the code to parse dates with a specific format 'YYYY-MM-DD'.

Pandas
df['date'] = pd.to_datetime(df['date'], format=[1])
Drag options to blanks, or click blank then click option'
A'%Y-%m-%d'
B'%d/%m/%Y'
C'%m-%d-%Y'
D'%Y/%d/%m'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong order of year, month, day in the format string.
Using slashes instead of dashes when the date string uses dashes.
3fill in blank
hard

Fix the error in the code to convert the 'date' column to datetime, allowing errors to be set as NaT.

Pandas
df['date'] = pd.to_datetime(df['date'], errors=[1])
Drag options to blanks, or click blank then click option'
A'raise'
B'ignore'
C'coerce'
D'skip'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'raise' which causes the code to stop on errors.
Using 'ignore' which returns the original data without conversion.
4fill in blank
hard

Fill both blanks to convert the 'date' column to datetime and extract the year into a new column.

Pandas
df['date'] = pd.to_datetime(df['date'], [1])
df['year'] = df['date'].[2]
Drag options to blanks, or click blank then click option'
Aerrors='coerce'
Berrors='ignore'
Cdt.year
Ddt.month
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong error handling options.
Trying to access year without using the dt accessor.
5fill in blank
hard

Fill all three blanks to convert 'date' column with a format, coerce errors, and extract month name.

Pandas
df['date'] = pd.to_datetime(df['date'], format=[1], errors=[2])
df['month_name'] = df['date'].[3]
Drag options to blanks, or click blank then click option'
A'%d-%m-%Y'
B'coerce'
Cdt.month_name()
D'ignore'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong format string for the date.
Not coercing errors causing exceptions.
Trying to get month name without using dt accessor.