0
0
Data Analysis Pythondata~10 mins

Why time-based analysis reveals trends in Data Analysis Python - Test Your Understanding

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.

Data Analysis Python
df['date'] = pd.to_datetime(df['[1]'])
Drag options to blanks, or click blank then click option'
Atime
Btimestamp
Cdate
Dday
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong column name like 'time' or 'timestamp'.
2fill in blank
medium

Complete the code to set the 'date' column as the DataFrame index.

Data Analysis Python
df = df.set_index('[1]')
Drag options to blanks, or click blank then click option'
Atime
Bdate
Cindex
Dtimestamp
Attempts:
3 left
💡 Hint
Common Mistakes
Setting the wrong column as index.
3fill in blank
hard

Fix the error in resampling the data by month and calculating the mean.

Data Analysis Python
monthly_avg = df.resample('[1]').mean()
Drag options to blanks, or click blank then click option'
AM
BW
CD
DY
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'D' or 'W' instead of 'M' for monthly data.
4fill in blank
hard

Fill both blanks to create a dictionary of average sales per month for products with sales greater than 100.

Data Analysis Python
monthly_sales = {product: df[df['product'] == product].resample([1]).[2]() for product in df['product'].unique() if df[df['product'] == product]['sales'].mean() > 100}
Drag options to blanks, or click blank then click option'
A'M'
Bmean
Csum
D'W'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sum' instead of 'mean' for average.
5fill in blank
hard

Fill all three blanks to filter data for dates after 2020-01-01, resample weekly, and calculate total sales.

Data Analysis Python
filtered = df[df.index > [1]]
weekly_sales = filtered.resample([2])['sales'].[3]()
Drag options to blanks, or click blank then click option'
A'2020-01-01'
B'W'
Csum
D'2021-01-01'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong date or resampling frequency.