0
0
Pandasdata~10 mins

Resampling with groupby for time data 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.to_datetime(df['[1]'])
Drag options to blanks, or click blank then click option'
Atime
Bdate
Ctimestamp
Ddatetime
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong column name like 'time' or 'timestamp'.
Not converting the column to datetime before resampling.
2fill in blank
medium

Complete 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'
Adate
Btime
Cindex
Dtimestamp
Attempts:
3 left
💡 Hint
Common Mistakes
Setting a non-datetime column as index.
Not setting any index before resampling.
3fill in blank
hard

Fix the error in the code to resample the data by month and calculate the mean.

Pandas
monthly_mean = df.resample('[1]').mean()
Drag options to blanks, or click blank then click option'
AM
BD
CW
DY
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'W' or 'D' instead of 'M' for monthly resampling.
Not calling the aggregation function after resampling.
4fill in blank
hard

Fill both blanks to group data by 'category' and resample by week, calculating the sum.

Pandas
weekly_sum = df.groupby('[1]').resample('[2]').sum()
Drag options to blanks, or click blank then click option'
Acategory
Bdate
CW
DM
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'date' instead of 'category' for grouping.
Using 'M' instead of 'W' for weekly resampling.
5fill in blank
hard

Fill all three blanks to group by 'region', resample by day, and calculate the maximum value.

Pandas
daily_max = df.groupby('[1]').resample('[2]').[3]()
Drag options to blanks, or click blank then click option'
Aregion
BD
Cmax
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sum' instead of 'max' for aggregation.
Using wrong group or resample parameters.