From 32a5c6a4eb543ab44059f6f8e891312477e5a3bd Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Fri, 10 Apr 2026 17:50:44 +0100 Subject: [PATCH 1/2] Update to add get_loc explainer - Also added version fixes to allow workflows to run --- episodes/07-pandas_essential.md | 6 ++++-- renv/profiles/lesson-requirements/renv.lock | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/episodes/07-pandas_essential.md b/episodes/07-pandas_essential.md index a80167c..4f8b52e 100644 --- a/episodes/07-pandas_essential.md +++ b/episodes/07-pandas_essential.md @@ -128,13 +128,15 @@ or: print(data.iloc[0, :]) ``` -The `:` character by itself is shorthand to indicate all elements across that indice, but it can also be combined with index values or column headers to specify a slice of the DataArray: +Note that here we knew that Albania was the first country in the DataFrame, so we were able to ask for the first column (0). If you needed to know the column ID for a particular country, you could do this using `get_loc()`, e.g. `data.index.get_loc("France")` should tell you the column ID value for France. + +The `:` character by itself is shorthand to indicate all elements across that index, but it can also be combined with index values or column headers to specify a slice of the DataArray: ```python print(data.loc["Albania", 'gdpPercap_1962':'gdpPercap_1972']) ``` -If either end of the slice definition is omitted, then the slice will run to the end of that indice (just as it does for `:` by itself): +If either end of the slice definition is omitted, then the slice will run to the end of that index (just as it does for `:` by itself): ```python print(data.loc["Albania", 'gdpPercap_1962':]) diff --git a/renv/profiles/lesson-requirements/renv.lock b/renv/profiles/lesson-requirements/renv.lock index 537f45a..fbd452e 100644 --- a/renv/profiles/lesson-requirements/renv.lock +++ b/renv/profiles/lesson-requirements/renv.lock @@ -522,7 +522,7 @@ }, "knitr": { "Package": "knitr", - "Version": "1.49", + "Version": "1.51", "Source": "Repository", "Type": "Package", "Title": "A General-Purpose Package for Dynamic Report Generation in R", @@ -808,7 +808,7 @@ }, "rmarkdown": { "Package": "rmarkdown", - "Version": "2.29", + "Version": "2.31", "Source": "Repository", "Type": "Package", "Title": "Dynamic Documents for R", @@ -925,7 +925,7 @@ }, "xfun": { "Package": "xfun", - "Version": "0.51", + "Version": "0.57", "Source": "Repository", "Type": "Package", "Title": "Supporting Functions for Packages Maintained by 'Yihui Xie'", From 8f6bbe0ecf29c8c79fe1282fe0918aaddcf20439 Mon Sep 17 00:00:00 2001 From: Andrew Gait Date: Mon, 13 Apr 2026 12:46:35 +0100 Subject: [PATCH 2/2] Move example code into block --- episodes/07-pandas_essential.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/episodes/07-pandas_essential.md b/episodes/07-pandas_essential.md index 9936b9b..6da4492 100644 --- a/episodes/07-pandas_essential.md +++ b/episodes/07-pandas_essential.md @@ -128,7 +128,11 @@ or: print(df.iloc[0, :]) ``` -Note that here we knew that Albania was the first country in the DataFrame, so we were able to ask for the first column (0). If you needed to know the column ID for a particular country, you could do this using `get_loc()`, e.g. `data.index.get_loc("France")` should tell you the column ID value for France. +Note that here we knew that Albania was the first country in the DataFrame, so we were able to ask for the first column (0). If you needed to know the column ID for a particular country, you could do this using `get_loc()`, e.g. to get the column ID value for France: + +```python +df.index.get_loc("France") +``` The `:` character by itself is shorthand to indicate all elements across that index, but it can also be combined with index values or column headers to specify a slice of the DataArray: