Skip to content

Commit

Permalink
fix deprecated map dataset, problem set issue
Browse files Browse the repository at this point in the history
  • Loading branch information
doctor-phil committed Nov 4, 2024
1 parent 7d81f50 commit f2b7504
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
3 changes: 3 additions & 0 deletions lectures/pandas/timeseries.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ kernelspec:

# Time series

**Co-author**
> - [Philip Solimine, *UBC*](https://www.psolimine.net)
**Prerequisites**

- {doc}`Python functions <../python_fundamentals/functions>`
Expand Down
2 changes: 1 addition & 1 deletion lectures/problem_sets/problem_set_8.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ahs.info()
```{code-cell} python
# dataframe of variable descriptions
ahs_doc = pd.read_csv("https://datascience.quantecon.org/assets/data/ahs-doc.csv", encoding="latin1")
with pd.option_context('display.max_rows', None, 'display.max_columns', None, 'max_colwidth', -1):
with pd.option_context('display.max_rows', None, 'display.max_columns', None, 'max_colwidth', None):
display(ahs_doc[["Variable","Question","Description","Associated.Response.Codes"]])
```

Expand Down
29 changes: 15 additions & 14 deletions lectures/tools/maps.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ kernelspec:

**Co-author**
> - [Kim Ruhl *University of Wisconsin*](http://kimjruhl.com)
> - [Philip Solimine *UBC*](https://www.psolimine.net)
**Prerequisites**

Expand Down Expand Up @@ -125,24 +126,24 @@ that we use here.
The file provides the outlines of countries, over which we'll plot the city locations
from our GeoDataFrame.

Luckily, `geopandas` already comes bundled with this data, so we don't
have to hunt it down!
Luckily, Natural Earth has already done the hard work of creating these files, and we can pull them directly from their website.

```{code-cell} python
# Grab low resolution world file
world = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))
world = world.set_index("iso_a3")
# Grab low resolution world file from NACIS
url = "https://naciscdn.org/naturalearth/110m/cultural/ne_110m_admin_0_countries.zip"
world = gpd.read_file(url)[['SOV_A3', 'POP_EST', 'CONTINENT', 'NAME', 'GDP_MD', 'geometry']]
world = world.set_index("SOV_A3")
print(world.columns)
world.head()
```

`world` is a GeoDataFrame with the following columns:

* `pop_est`: Contains a population estimate for the country
* `continent`: The country's continent
* `name`: The country's name
* `iso_a3`: The country's 3 letter abbreviation (we made this the index)
* `gdp_md_est`: An estimate of country's GDP
* `POP_EST`: Contains a population estimate for the country
* `CONTINENT`: The country's continent
* `NAME`: The country's name
* `SOV_A3`: The country's 3 letter abbreviation (we made this the index)
* `GDP_MD`: The most recent estimate of country's GDP
* `geometry`: A `POLYGON` for each country (we will learn more about these soon)

```{code-cell} python
Expand Down Expand Up @@ -201,7 +202,7 @@ This is a more complex shape than Albania and thus required more points.
fig, gax = plt.subplots(figsize=(10,10))
# By only plotting rows in which the continent is 'South America' we only plot SA.
world.query("continent == 'South America'").plot(ax=gax, edgecolor='black',color='white')
world.query("CONTINENT == 'South America'").plot(ax=gax, edgecolor='black',color='white')
# By the way, if you haven't read the book 'longitude' by Dava Sobel, you should...
gax.set_xlabel('longitude')
Expand Down Expand Up @@ -234,7 +235,7 @@ fig, gax = plt.subplots(figsize=(10,10))
# By only plotting rows in which the continent is 'South America' we only plot, well,
# South America.
world.query("continent == 'South America'").plot(ax = gax, edgecolor='black', color='white')
world.query("CONTINENT == 'South America'").plot(ax = gax, edgecolor='black', color='white')
# This plot the cities. It's the same syntax, but we are plotting from a different GeoDataFrame.
# I want the cities as pale red dots.
Expand All @@ -260,7 +261,7 @@ Finally, we might want to consider annotating the cities so we know which cities
fig, gax = plt.subplots(figsize=(10,10))
# By only plotting rows in which the continent is 'South America' we only plot, well, South America.
world.query("continent == 'South America'").plot(ax = gax, edgecolor='black', color='white')
world.query("CONTINENT == 'South America'").plot(ax = gax, edgecolor='black', color='white')
# This plot the cities. It's the same syntax, but we are plotting from a different GeoDataFrame. I want the
# cities as pale red dots.
Expand Down
3 changes: 3 additions & 0 deletions lectures/tools/matplotlib.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ kernelspec:

# Intermediate Plotting

**Co-author**
> - [Philip Solimine, *UBC*](https://www.psolimine.net)
**Prerequisites**

- {doc}`Introduction <../pandas/intro>`
Expand Down

0 comments on commit f2b7504

Please sign in to comment.