Skip to content

Commit

Permalink
Update groupby.md
Browse files Browse the repository at this point in the history
  • Loading branch information
doctor-phil committed Nov 5, 2024
1 parent cca9326 commit 0f23a51
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lectures/pandas/groupby.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def smallest_by_b(df):
```

```{code-cell} python
gbA.apply(smallest_by_b)
gbA.apply(smallest_by_b, include_groups=False)
```

Notice that the return value from applying our series transform to `gbA`
Expand Down Expand Up @@ -250,7 +250,7 @@ index and a `Date` column added.
df2 = df.copy()
df2["Date"] = pd.date_range(
start=pd.Timestamp.today().strftime("%m/%d/%Y"),
freq="BQ",
freq="BQE",
periods=df.shape[0]
)
df2 = df2.set_index("A")
Expand All @@ -260,7 +260,7 @@ df2
We can group by year.

```{code-cell} python
df2.groupby(pd.Grouper(key="Date", freq="A")).count()
df2.groupby(pd.Grouper(key="Date", freq="YE")).count()
```

We can group by the `A` level of the index.
Expand All @@ -272,14 +272,14 @@ df2.groupby(pd.Grouper(level="A")).count()
We can combine these to group by both.

```{code-cell} python
df2.groupby([pd.Grouper(key="Date", freq="A"), pd.Grouper(level="A")]).count()
df2.groupby([pd.Grouper(key="Date", freq="YE"), pd.Grouper(level="A")]).count()
```

And we can combine `pd.Grouper` with a string, where the string
denotes a column name

```{code-cell} python
df2.groupby([pd.Grouper(key="Date", freq="A"), "B"]).count()
df2.groupby([pd.Grouper(key="Date", freq="YE"), "B"]).count()
```

## Case Study: Airline Delays
Expand Down

0 comments on commit 0f23a51

Please sign in to comment.