GitHub

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`.

Read the original on github.com ↗