123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- import pandas as pd
- import rpy2.robjects as robjects
-
- #hellooo
-
- robjects.r('''
- library(tidycensus)
- library(tidyverse)
-
- tableYear = 2020
-
- #log on with API
- census_api_key("7a853acf81fd5758228680556ac831138c40b83e")
-
- #load variables
- pueblos = 78
- variables = load_variables(2020,"acs5/profile")
- codes = variables$name
- label0 = variables$label
-
- #view variables
- #varTable = table(variables$concept)
- #write.table(varTable, file = "cat.txt", sep = ",", quote = FALSE, row.names = F)
-
- #pull all tables with every variable
-
- test = get_acs(geography = "county",
- state = "PR",
- year = tableYear,
- variables = codes)
-
- #add label column
- #create empty vector
- labelCol = c()
-
- #amount of GEOIDS
- for (x in 1:pueblos){
- labelCol = c(labelCol, label0)
- }
-
- #combine test and cols
- test["label"] = labelCol
-
- #rearrange cols
- test = test[c("NAME","label","variable","estimate","moe","GEOID")]
-
- GEOIDS = table(test$GEOID)
-
- #omit NA rows
- noNA = na.omit(test)
-
- DP02table = noNA %>% filter(startsWith(variable,"DP02"))
-
- DP03table = noNA %>% filter(startsWith(variable,"DP03"))
-
- DP04table = noNA %>% filter(startsWith(variable,"DP04"))
-
- DP05table = noNA %>% filter(startsWith(variable,"DP05"))
- ''')
-
- table02 = robjects.r('''DP02table''')
- table03 = robjects.r('''DP03table''')
- table04 = robjects.r('''DP04table''')
- table05 = robjects.r('''DP05table''')
-
- print(table02)
|