강의 홍보
1줄 요약
- 오픈 데이터로 활용하여 시계열 데이터를 확보해보자.
동기 부여
- Pandas 공식 홈페이지가 살짝 바뀐 듯 하였다.

- 시계열 데이터를 다루는 페이지를 확인하던 중 open air quality data API가 있는 것을 확인하였다.
라이브러리 설치
$ pip install py-openaq
Collecting py-openaq
Downloading py-openaq-1.1.0.tar.gz (7.9 kB)
Building wheels for collected packages: py-openaq
Building wheel for py-openaq (setup.py) ... done
Created wheel for py-openaq: filename=py_openaq-1.1.0-py3-none-any.whl size=9036 sha256=1d5011bd3ef180c93d275081f6f5ad20d569c9f7ce2982eabaaeee7307070b75
Stored in directory: /Users/evan/Library/Caches/pip/wheels/01/1d/be/6b6a0ee792bbc9138aeb645707cdad8da741bb2d789beb04d9
Successfully built py-openaq
Installing collected packages: py-openaq
Successfully installed py-openaq-1.1.0
데이터 불러오기
import openaq
api = openaq.OpenAQ()
location = "FR04014"
date_from = "2019-05-07T01:00:00"
date_to = "2019-06-21T00:00:00"
parameter = "no2"
FR04014_results = api.measurements(location=location,
parameter=parameter,
date_from=date_from,
date_to=date_to,
limit=10000,
df=True,
index='local')
print(FR04014_results.shape)
FR04014_results.head()
(1002, 9)
|
location |
parameter |
value |
unit |
country |
city |
date.utc |
coordinates.latitude |
coordinates.longitude |
| date.local |
|
|
|
|
|
|
|
|
|
| 2019-06-21 02:00:00 |
FR04014 |
no2 |
20.0 |
b'\xc2\xb5g/m\xc2\xb3' |
FR |
Paris |
2019-06-21 00:00:00+00:00 |
48.837243 |
2.393902 |
| 2019-06-21 01:00:00 |
FR04014 |
no2 |
21.8 |
b'\xc2\xb5g/m\xc2\xb3' |
FR |
Paris |
2019-06-20 23:00:00+00:00 |
48.837243 |
2.393902 |
| 2019-06-21 00:00:00 |
FR04014 |
no2 |
26.5 |
b'\xc2\xb5g/m\xc2\xb3' |
FR |
Paris |
2019-06-20 22:00:00+00:00 |
48.837243 |
2.393902 |
| 2019-06-20 23:00:00 |
FR04014 |
no2 |
24.9 |
b'\xc2\xb5g/m\xc2\xb3' |
FR |
Paris |
2019-06-20 21:00:00+00:00 |
48.837243 |
2.393902 |
| 2019-06-20 22:00:00 |
FR04014 |
no2 |
21.4 |
b'\xc2\xb5g/m\xc2\xb3' |
FR |
Paris |
2019-06-20 20:00:00+00:00 |
48.837243 |
2.393902 |
- 정상적으로 데이터가 불러오진 것을 확인할 수 있다.
- 다음은 3개의 데이터셋을 만들어서 합친 후, 시계열 데이터 핸들링을 연습해보독 한다.
Reference
HP-Nunes.(2020). An Introduction to Data Collection: REST APIs with Python & Pizzas, Medium, Retrieved from https://medium.com/@geocuriosity/an-introduction-to-data-collection-rest-apis-with-python-pizzas-7b682cef676c