0
0
Pandasdata~10 mins

Extracting year, month, day 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 extract the year from the 'date' column in the DataFrame.

Pandas
df['year'] = df['date'].dt.[1]
Drag options to blanks, or click blank then click option'
Ayear
Bmonth
Cday
Dhour
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'month' or 'day' instead of 'year'.
Forgetting to use the dt accessor.
2fill in blank
medium

Complete the code to extract the month from the 'date' column in the DataFrame.

Pandas
df['month'] = df['date'].dt.[1]
Drag options to blanks, or click blank then click option'
Aminute
Bday
Cmonth
Dyear
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'day' or 'year' instead of 'month'.
Forgetting to use the dt accessor.
3fill in blank
hard

Fix the error in the code to extract the day from the 'date' column in the DataFrame.

Pandas
df['day'] = df['date'].[1]
Drag options to blanks, or click blank then click option'
Aday
Bdt.day()
Cday()
Ddt.day
Attempts:
3 left
💡 Hint
Common Mistakes
Using df['date'].day without dt accessor.
Using parentheses like dt.day() which is invalid.
4fill in blank
hard

Fill both blanks to create a dictionary with words as keys and their lengths as values, but only for words longer than 3 letters.

Pandas
lengths = {word: [1] for word in words if [2] > 3}
Drag options to blanks, or click blank then click option'
Alen(word)
Bword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Checking the word instead of its length in the condition.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values, only for words longer than 3 letters.

Pandas
result = { [1]: [2] for word in words if [3] > 3 }
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the original word as key instead of uppercase.
Using the word instead of its length as value.
Not filtering words by length.