0
0
Pandasdata~10 mins

Time series analysis patterns 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 a datetime type.

Pandas
df['date'] = pd.[1](df['date'])
Drag options to blanks, or click blank then click option'
Ato_string
Bto_datetime
Cto_numeric
Dto_list
Attempts:
3 left
💡 Hint
Common Mistakes
Using to_string instead of to_datetime.
Trying to convert with to_numeric which is for numbers.
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'
A'index'
B'time'
C'date'
D'timestamp'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong column name like 'time' or 'timestamp'.
Not using quotes around the column name.
3fill in blank
hard

Fix 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'
A'M'
B'W'
C'D'
D'Y'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'D' for day or 'W' for week instead of month.
Using lowercase 'm' which is not valid.
4fill in blank
hard

Fill 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'
Arolling
B3
C5
Dshift
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'shift' instead of 'rolling'.
Using window size 5 instead of 3.
5fill in blank
hard

Fill 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'
Amax
Byear
Dmin
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'min' instead of 'max' for maximum values.
Using wrong attribute instead of 'year'.