-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathcontextify.py
executable file
·37 lines (28 loc) · 985 Bytes
/
contextify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python3
import pandas as pd
"""
Example of adding context to a table
"""
import ukcensusapi.Nomisweb as Api
def main():
api = Api.Nomisweb("/tmp/UKCensusAPI")
print("Nomisweb census data geographical query example")
print("See README.md for details on how to use this package")
# Heres predefined query on a small geographical area
table = "KS401EW"
query_params = {}
query_params["CELL"] = "7...13"
query_params["date"] = "latest"
query_params["RURAL_URBAN"] = "0"
query_params["select"] = "GEOGRAPHY_CODE,CELL,OBS_VALUE"
query_params["geography"] = "1245710558...1245710560"
query_params["MEASURES"] = "20100"
ks401 = api.get_data(table, query_params)
# display the first ten rows
print(ks401.head(10))
# Now add context - the desriptions of the values (7 to 13) in the CELL column
api.contextify(table, "CELL", ks401)
print(ks401.head(10))
ks401.to_csv("/tmp/contextified", sep="\t")
if __name__ == "__main__":
main()