Pandas & Data Analysis·Practice drills 3

Drill 6: Recall — Analysis project

Close the lesson and reproduce the example from memory.

Beginner 5 min read Lesson 70 of 300 Challenge included
What you will be able to do
  • Close the lesson and reproduce the example from memory.

Practice task

Close the lesson and reproduce the example from memory.

analysis.pyPython
import pandas as pd

raw = pd.read_csv('lessons.csv', parse_dates=['published_at'])
clean = (
    raw.drop_duplicates()
    .dropna(subset=['course', 'minutes'])
    .assign(month=lambda d: d['published_at'].dt.to_period('M'))
)

answer = (
    clean.groupby(['month', 'course'])['minutes']
    .agg(['size', 'mean'])
    .reset_index()
    .sort_values('mean', ascending=False)
)

print(clean.shape, '->', answer.head(10))
Your turn

Write your answer

Easy

Close the lesson and reproduce the example from memory.

TEXT · starter
Your answer…
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Lesson 70 of 300 · 0% of course