From f1b3142ff05df6d4484c039bcdc65b12c1549cf6 Mon Sep 17 00:00:00 2001 From: Matt McKay Date: Tue, 10 Feb 2026 14:39:59 +1100 Subject: [PATCH 1/2] 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) --- environment.yml | 1 + lectures/pandas.md | 4 ++-- lectures/pandas_panel.md | 10 +++++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/environment.yml b/environment.yml index 5db4b19e..f3b28b11 100644 --- a/environment.yml +++ b/environment.yml @@ -4,6 +4,7 @@ channels: dependencies: - python=3.13 - anaconda=2025.12 + - pandas>=3 - pip - pip: - jupyter-book>=1.0.4post1,<2.0 diff --git a/lectures/pandas.md b/lectures/pandas.md index 3d2c809d..0a5fb258 100644 --- a/lectures/pandas.md +++ b/lectures/pandas.md @@ -349,10 +349,10 @@ df.loc[complexCondition] The ability to make changes in dataframes is important to generate a clean dataset for future analysis. -**1.** We can use `df.where()` conveniently to "keep" the rows we have selected and replace the rest rows with any other values +**1.** We can use `df.where()` conveniently to "keep" the rows we have selected and replace the rest rows with `NaN` ```{code-cell} ipython3 -df.where(df.POP >= 20000, False) +df.where(df.POP >= 20000) ``` **2.** We can simply use `.loc[]` to specify the column that we want to modify, and assign values diff --git a/lectures/pandas_panel.md b/lectures/pandas_panel.md index 8bb6b29e..8cb3b762 100644 --- a/lectures/pandas_panel.md +++ b/lectures/pandas_panel.md @@ -150,14 +150,14 @@ the row index (`.unstack()` works in the opposite direction - try it out) ```{code-cell} ipython3 -realwage.stack(future_stack=True).head() +realwage.stack().head() ``` We can also pass in an argument to select the level we would like to stack ```{code-cell} ipython3 -realwage.stack(level='Country', future_stack=True).head() # future_stack=True is required until pandas>3.0 +realwage.stack(level='Country').head() ``` 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 `MultiIndex` creates a cross-section of our panel data ```{code-cell} ipython3 -realwage.loc['2015'].stack(level=(1, 2), future_stack=True).transpose().head() # future_stack=True is required until pandas>3.0 +realwage.loc['2015'].stack(level=(1, 2)).transpose().head() ``` For the rest of lecture, we will work with a dataframe of the hourly @@ -401,7 +401,7 @@ plt.show() We can also specify a level of the `MultiIndex` (in the column axis) to aggregate over. -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. +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. ```{code-cell} ipython3 merged.T.groupby(level='Continent').mean().head() @@ -432,7 +432,7 @@ plt.show() summary statistics ```{code-cell} ipython3 -merged.stack(future_stack=True).describe() +merged.stack().describe() ``` This is a simplified way to use `groupby`. From cf9744164256d1f65d0ffada61df49ad5f4eea53 Mon Sep 17 00:00:00 2001 From: Matt McKay Date: Tue, 10 Feb 2026 14:45:37 +1100 Subject: [PATCH 2/2] Install pandas via pip instead of conda Conda doesn't have pandas 3.0 in default channel yet, so installing via pip. --- environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index f3b28b11..ee00f91e 100644 --- a/environment.yml +++ b/environment.yml @@ -4,9 +4,9 @@ channels: dependencies: - python=3.13 - anaconda=2025.12 - - pandas>=3 - pip - pip: + - pandas>=3 - jupyter-book>=1.0.4post1,<2.0 - quantecon-book-theme==0.15.1 - sphinx-tojupyter==0.6.0