Skip to content

Commit f1b3142

Browse files
committed
Update lectures for pandas 3.0 compatibility
- Remove future_stack=True from .stack() calls (now default in pandas 3.0) - Update groupby axis text from 'deprecated' to 'removed' - Fix df.where() example to avoid str dtype conflict with non-string replacement - Add pandas>=3 to environment.yml (not included in anaconda=2025.12)
1 parent 3e4f703 commit f1b3142

3 files changed

Lines changed: 8 additions & 7 deletions

File tree

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ channels:
44
dependencies:
55
- python=3.13
66
- anaconda=2025.12
7+
- pandas>=3
78
- pip
89
- pip:
910
- jupyter-book>=1.0.4post1,<2.0

lectures/pandas.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,10 @@ df.loc[complexCondition]
349349
The ability to make changes in dataframes is important to generate a clean dataset for future analysis.
350350

351351

352-
**1.** We can use `df.where()` conveniently to "keep" the rows we have selected and replace the rest rows with any other values
352+
**1.** We can use `df.where()` conveniently to "keep" the rows we have selected and replace the rest rows with `NaN`
353353

354354
```{code-cell} ipython3
355-
df.where(df.POP >= 20000, False)
355+
df.where(df.POP >= 20000)
356356
```
357357

358358
**2.** We can simply use `.loc[]` to specify the column that we want to modify, and assign values

lectures/pandas_panel.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,14 @@ the row index (`.unstack()` works in the opposite direction - try it
150150
out)
151151

152152
```{code-cell} ipython3
153-
realwage.stack(future_stack=True).head()
153+
realwage.stack().head()
154154
```
155155

156156
We can also pass in an argument to select the level we would like to
157157
stack
158158

159159
```{code-cell} ipython3
160-
realwage.stack(level='Country', future_stack=True).head() # future_stack=True is required until pandas>3.0
160+
realwage.stack(level='Country').head()
161161
```
162162

163163
Using a `DatetimeIndex` makes it easy to select a particular time
@@ -167,7 +167,7 @@ Selecting one year and stacking the two lower levels of the
167167
`MultiIndex` creates a cross-section of our panel data
168168

169169
```{code-cell} ipython3
170-
realwage.loc['2015'].stack(level=(1, 2), future_stack=True).transpose().head() # future_stack=True is required until pandas>3.0
170+
realwage.loc['2015'].stack(level=(1, 2)).transpose().head()
171171
```
172172

173173
For the rest of lecture, we will work with a dataframe of the hourly
@@ -401,7 +401,7 @@ plt.show()
401401
We can also specify a level of the `MultiIndex` (in the column axis)
402402
to aggregate over.
403403

404-
In the case of `groupby` we need to use `.T` to transpose the columns into rows as `pandas` has deprecated the use of `axis=1` in the `groupby` method.
404+
In the case of `groupby` we need to use `.T` to transpose the columns into rows as `pandas` has removed support for `axis=1` in the `groupby` method.
405405

406406
```{code-cell} ipython3
407407
merged.T.groupby(level='Continent').mean().head()
@@ -432,7 +432,7 @@ plt.show()
432432
summary statistics
433433

434434
```{code-cell} ipython3
435-
merged.stack(future_stack=True).describe()
435+
merged.stack().describe()
436436
```
437437

438438
This is a simplified way to use `groupby`.

0 commit comments

Comments
 (0)