Skip to content

Commit d6519d9

Browse files
authored
Merge pull request #59 from UoMResearchIT/23-add-note-on-getting-index-from-name
Update to add get_loc explainer
2 parents 312e3c3 + 8f6bbe0 commit d6519d9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

episodes/07-pandas_essential.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,19 @@ or:
128128
print(df.iloc[0, :])
129129
```
130130

131-
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:
131+
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:
132+
133+
```python
134+
df.index.get_loc("France")
135+
```
136+
137+
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:
132138

133139
```python
134140
print(df.loc["Albania", 'gdpPercap_1962':'gdpPercap_1972'])
135141
```
136142

137-
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):
143+
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):
138144

139145
```python
140146
print(df.loc["Albania", 'gdpPercap_1962':])

0 commit comments

Comments
 (0)