Skip to content

Commit

Permalink
Merge branch 'patches' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
doctor-phil authored Nov 5, 2024
2 parents 31ccb5c + 0f23a51 commit b80795b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lectures/pandas/data_clean.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,12 @@ df.fillna(value=100)

```{code-cell} python
# use the _next_ valid observation to fill the missing data
df.fillna(method="bfill")
df.bfill() # in new versions of pandas, bfill will directly fill missing data
```

```{code-cell} python
# use the _previous_ valid observation to fill missing data
df.fillna(method="ffill")
df.ffill()
```

We will see more examples of dealing with missing data in future
Expand Down
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
2 changes: 1 addition & 1 deletion lectures/pandas/timeseries.md
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ Below are some examples.

```{code-cell} python
# business quarter
btc_usd.resample("BQ").mean()
btc_usd.resample("BQE").mean()
```

Note that unlike with `rolling`, a single number is returned for
Expand Down
1 change: 1 addition & 0 deletions lectures/tools/maps.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ kernelspec:

**Co-author**
> - [Kim Ruhl *University of Wisconsin*](http://kimjruhl.com)
> - [Philip Solimine *UBC*](https://www.psolimine.net)
**Prerequisites**

Expand Down

1 comment on commit b80795b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.