Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to convert the 'date' column to a datetime type.
Pandas
df['date'] = pd.[1](df['date'])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using to_string instead of to_datetime.
Trying to convert with to_numeric which is for numbers.
✗ Incorrect
Use pd.to_datetime to convert a column to datetime format in pandas.
2fill in blank
mediumComplete the code to set the 'date' column as the DataFrame index.
Pandas
df = df.set_index([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong column name like 'time' or 'timestamp'.
Not using quotes around the column name.
✗ Incorrect
Setting the 'date' column as index helps with time series operations.
3fill in blank
hardFix the error in the code to resample the data by month and calculate the mean.
Pandas
monthly = df.resample([1]).mean() Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'D' for day or 'W' for week instead of month.
Using lowercase 'm' which is not valid.
✗ Incorrect
Use 'M' to resample data by month in pandas.
4fill in blank
hardFill both blanks to create a rolling average with a window of 3 days.
Pandas
rolling_avg = df['value'].[1](window=[2]).mean()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'shift' instead of 'rolling'.
Using window size 5 instead of 3.
✗ Incorrect
Use rolling(window=3) to calculate a rolling average over 3 days.
5fill in blank
hardFill all three blanks to create a dictionary of max values for each year.
Pandas
yearly_max = {year: group['value'].[1]() for year, group in df.groupby(df.index.[2]) if group['value'].[3]() > 50} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'min' instead of 'max' for maximum values.
Using wrong attribute instead of 'year'.
✗ Incorrect
This code groups data by year, then finds the max value for each year where the max is greater than 50.