Complete the code to convert the 'date' column to datetime format.
import pandas as pd df = pd.DataFrame({'date': ['2023-01-01', '2023-02-15', '2023-03-20']}) df['date'] = pd.to_datetime(df['date'][1])
To convert a column to datetime, use pd.to_datetime() with parentheses.
Complete the code to extract the year from the 'date' column into a new column 'year'.
df['year'] = df['date'].dt.[1]
dt accessor.The dt.year attribute extracts the year from datetime values.
Fix the error in extracting the weekday name from the 'date' column.
df['weekday'] = df['date'].dt.[1]()
weekday_name() which does not exist.weekday which returns an integer.The correct method to get the weekday name is dt.day_name().
Fill both blanks to create a dictionary with words as keys and their lengths as values, but only for words longer than 4 letters.
words = ['apple', 'bat', 'carrot', 'dog', 'elephant'] lengths = { [1] : [2] for word in words if len(word) > 4 }
The dictionary comprehension uses the word as key and its length as value.
Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values, but only for words with length greater than 3.
words = ['sun', 'moon', 'star', 'sky', 'planet'] result = { [1] : [2] for word in words if len(word) [3] 3 }
The dictionary comprehension uses uppercase words as keys, their lengths as values, and filters words longer than 3 letters.