diff --git a/environment.yml b/environment.yml index 5db4b19e..ee00f91e 100644 --- a/environment.yml +++ b/environment.yml @@ -6,6 +6,7 @@ dependencies: - anaconda=2025.12 - pip - pip: + - pandas>=3 - jupyter-book>=1.0.4post1,<2.0 - quantecon-book-theme==0.15.1 - sphinx-tojupyter==0.6.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`.