Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong column name like 'time' or 'timestamp'.
✗ Incorrect
The 'date' column must be converted to datetime to analyze trends over time.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Setting the wrong column as index.
✗ Incorrect
Setting 'date' as index helps in time-based analysis and plotting.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'D' or 'W' instead of 'M' for monthly data.
✗ Incorrect
'M' stands for month in resampling frequency strings.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sum' instead of 'mean' for average.
✗ Incorrect
Resample by month ('M') and calculate the mean sales.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong date or resampling frequency.
✗ Incorrect
Filter dates after '2020-01-01', resample weekly ('W'), and sum sales.