Skip to content

Commit 811accd

Browse files
mmckyclaude
andauthored
[pandas, pandas_panel] Update lectures for pandas 3.0 compatibility (#470)
* [pandas, pandas_panel] Update lectures for pandas 3.0 compatibility anaconda 2026.06 (merged in #562) ships pandas 3.0.3, so the interim pandas>=3 pip pin and anaconda=2025.12 are no longer needed. This branch now carries only the lecture updates: - pandas_panel: drop redundant future_stack=True from .stack() calls (the new stacking layout is the default in pandas 3.0) - pandas_panel: text now says axis=1 in groupby is "removed" not "deprecated" (it is fully removed in 3.0) - pandas: df.where(df.POP >= 20000, False) -> df.where(df.POP >= 20000) so the example fills non-matching rows with NaN instead of scattering False through the string columns Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * Address Copilot grammar feedback - pandas: "replace the rest rows" -> "replace the remaining rows" - pandas_panel: add commas around the introductory phrase / before "as" to fix the run-on sentence about groupby axis=1 removal Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent d38394b commit 811accd

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

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 remaining 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)