Skip to content

Commit dc82cb0

Browse files
author
Susan Vanderplas
committed
Update code to download the data, along with the links to the data
1 parent 9f35164 commit dc82cb0

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

part-gen-prog/07-prog-data.qmd

+4-5
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ To look at this, we'll need a bit more data. I found a list of NYC zip codes by
460460

461461
```{r get-nyc-zip-borough, echo = F, include = F, eval = F}
462462
library(xml2)
463-
library(tidyverse)
463+
library(readr)
464464
page <- read_html("https://www.nycbynatives.com/nyc_info/new_york_city_zip_codes.php")
465465
nyc_zip_borough <- data.frame(ZipCode = c(xml_find_all(page, ".//tr/td[1]"),
466466
xml_find_all(page, ".//tr/td[4]")) %>%
@@ -471,15 +471,15 @@ nyc_zip_borough <- data.frame(ZipCode = c(xml_find_all(page, ".//tr/td[1]"),
471471
purrr::map_chr(xml_text) %>%
472472
stringr::str_trim()) %>%
473473
unique()
474-
write_csv(nyc_zip_borough, "data/nyc_zip_borough.csv")
474+
write_csv(nyc_zip_borough, file = file.path("../", "data", "nyc_zip_borough.csv"))
475475
```
476476

477477
::: panel-tabset
478478

479479
#### R {-}
480480

481481
```{r merge-dog-borough-info}
482-
borough_zip <- read_csv("https://raw.githubusercontent.com/srvanderplas/unl-stat850/main/data/nyc_zip_borough.csv")
482+
borough_zip <- read_csv("https://raw.githubusercontent.com/srvanderplas/stat-computing-r-python/main/data/nyc_zip_borough.csv")
483483
484484
# Remove the Borough column from dogs
485485
dogs <- dogs[, which(names(dogs) != "Borough")]
@@ -491,8 +491,7 @@ head(dogs)
491491
#### Python {-}
492492

493493
```{python merge-dog-borough-info-py}
494-
borough_zip = pd.read_csv("https://raw.githubusercontent.com/srvanderplas/unl-stat850/main/data/nyc_zip_borough.csv")
495-
494+
borough_zip = pd.read_csv("https://raw.githubusercontent.com/srvanderplas/stat-computing-r-python/main/data/nyc_zip_borough.csv")
496495
dogs = dogs.drop('Borough', axis = 1) # drop borough column
497496
dogs = pd.merge(dogs, borough_zip, on = 'ZipCode')
498497
dogs.head()

0 commit comments

Comments
 (0)