Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lectures/pandas.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions lectures/pandas_panel.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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`.
Expand Down
Loading