<jupyter_start><jupyter_text>Stat 133 Homework 9  Part I<jupyter_code>library(DataComputing)
library(rvest)
library(lubridate)
page = "List_of_nuclear_reactors"
xpath = '//*[@id="mw-content-text"]/table' 
table_list <- page %>%
  read_html() %>%
  html_nodes(xpath = xpath) %>%
  html_table(fill = TRUE)<jupyter_output><empty_output><jupyter_text>Find the table element<jupyter_code>table <- table_list[[23]]
head(table)
names(table)<jupyter_output><empty_output><jupyter_text>Look at it using View()<jupyter_code>new_names <- c("name", "reactor_no", "type", "model",
               "status", "net", "gross", "construction_start",
               "operation_start", "closure")
names(table) <- new_names
table <- table %>% filter(row_number() != 1)
head(table)<jupyter_output><empty_output><jupyter_text>A quick visualization<jupyter_code>table %>% 
  separate(construction_start, into=c("day", "month", "year"), sep=" ") %>%
  mutate(year=as.numeric(year)) %>%
  ggplot(aes(y=net, x=year, color=type)) + geom_point() + labs(x="construction start")<jupyter_output>Warning message:
: Too few values at 3 locations: 20, 21, 22Warning message:
: Removed 3 rows containing missing values (geom_point).<jupyter_text>Construction delays<jupyter_code>table %>% 
  separate(construction_start, into=c("day1", "month1", "year1"), sep=" ") %>%
  separate(operation_start, into=c("day2", "month2", "year2"), sep=" ") %>%
  mutate(year1=as.numeric(year1), year2=as.numeric(year2)) %>%
  ggplot() + geom_segment(aes(x=year1, xend=year2, y=name, yend=name)) + labs(x="construction start", y="reactor site")<jupyter_output>Warning message:
: Too few values at 3 locations: 20, 21, 22Warning message:
: Too few values at 5 locations: 20, 21, 22, 41, 51Warning message:
: Removed 5 rows containing missing values (geom_segment).
{'fraction_non_alphanumeric': 0.16804864566058597, 'fraction_numerical': 0.02542841348811498, 'mean_word_length': 6.801724137931035, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '29568', 'license': 'MIT', 'n_tokens_mistral': 699, 'n_tokens_neox': 633, 'n_words': 130, 'path': 'hw9/hw9.ipynb', 'repo_name': 'young-geng/stat133', 'size': '1809'}