|
@@ -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)
|