0
0
Pandasdata~10 mins

Resampling time series 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 resample the DataFrame to daily frequency and calculate the mean.

Pandas
daily_mean = df.resample([1]).mean()
Drag options to blanks, or click blank then click option'
A'D'
B'W'
C'M'
D'H'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'W' which resamples weekly instead of daily.
Using 'M' which resamples monthly instead of daily.
Using 'H' which resamples hourly instead of daily.
2fill in blank
medium

Complete the code to resample the DataFrame to monthly frequency and calculate the sum.

Pandas
monthly_sum = df.resample([1]).sum()
Drag options to blanks, or click blank then click option'
A'D'
B'Y'
C'Q'
D'M'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'D' which resamples daily instead of monthly.
Using 'Q' which resamples quarterly instead of monthly.
Using 'Y' which resamples yearly instead of monthly.
3fill in blank
hard

Fix the error in the code to resample the DataFrame to hourly frequency and calculate the mean.

Pandas
hourly_mean = df.resample([1]).mean()
Drag options to blanks, or click blank then click option'
A'h'
B'hour'
C'H'
D'hr'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase 'h' which is not recognized.
Using full words like 'hour' or abbreviations like 'hr' which are invalid.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each word to its length only if the length is greater than 3.

Pandas
lengths = {word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Blen(word) > 3
Cword
Dword > 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'word' instead of 'len(word)' for the value.
Using 'word > 3' which compares string to number and causes error.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase keys to values only if the value is greater than 0.

Pandas
result = {{ [1]: [2] for k, v in data.items() if v [3] 0 }}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using k.lower() instead of k.upper() for keys.
Using v < 0 or other operators that do not filter positive values.
Using k or v incorrectly in the comprehension.