andrea.nieves7 1 year ago
parent
commit
740b641071
2 changed files with 68 additions and 1 deletions
  1. 2
    1
      R.R
  2. 66
    0
      fetchTables.py

+ 2
- 1
R.R View File

@@ -7,6 +7,7 @@ tableYear = 2020
7 7
 census_api_key("7a853acf81fd5758228680556ac831138c40b83e")
8 8
 
9 9
 #load variables
10
+pueblos = 78
10 11
 variables = load_variables(2020,"acs5/profile")
11 12
 codes = variables$name
12 13
 label0 = variables$label
@@ -27,7 +28,7 @@ test = get_acs(geography = "county",
27 28
 labelCol = c()
28 29
 
29 30
 #amount of GEOIDS
30
-for (x in 1:78){
31
+for (x in 1:pueblos){
31 32
   labelCol = c(labelCol, label0)
32 33
 }
33 34
 

+ 66
- 0
fetchTables.py View File

@@ -0,0 +1,66 @@
1
+import pandas as pd
2
+import rpy2.robjects as robjects
3
+
4
+#hellooo
5
+
6
+robjects.r('''
7
+        library(tidycensus)
8
+library(tidyverse)
9
+
10
+tableYear = 2020
11
+
12
+#log on with API
13
+census_api_key("7a853acf81fd5758228680556ac831138c40b83e")
14
+
15
+#load variables
16
+pueblos = 78
17
+variables = load_variables(2020,"acs5/profile")
18
+codes = variables$name
19
+label0 = variables$label
20
+
21
+#view variables
22
+#varTable = table(variables$concept)
23
+#write.table(varTable, file = "cat.txt", sep = ",", quote = FALSE, row.names = F)
24
+
25
+#pull all tables with every variable
26
+  
27
+test = get_acs(geography = "county",
28
+               state = "PR",
29
+               year = tableYear,
30
+               variables = codes)
31
+
32
+#add label column
33
+#create empty vector 
34
+labelCol = c()
35
+
36
+#amount of GEOIDS
37
+for (x in 1:pueblos){
38
+  labelCol = c(labelCol, label0)
39
+}
40
+
41
+#combine test and cols
42
+test["label"] = labelCol
43
+
44
+#rearrange cols
45
+test = test[c("NAME","label","variable","estimate","moe","GEOID")]
46
+
47
+GEOIDS = table(test$GEOID)
48
+
49
+#omit NA rows
50
+noNA = na.omit(test)
51
+
52
+DP02table = noNA %>% filter(startsWith(variable,"DP02"))
53
+
54
+DP03table = noNA %>% filter(startsWith(variable,"DP03"))
55
+
56
+DP04table = noNA %>% filter(startsWith(variable,"DP04"))
57
+
58
+DP05table = noNA %>% filter(startsWith(variable,"DP05"))
59
+        ''')
60
+        
61
+table02 = robjects.r('''DP02table''')
62
+table03 = robjects.r('''DP03table''')
63
+table04 = robjects.r('''DP04table''')
64
+table05 = robjects.r('''DP05table''')
65
+
66
+print(table02)