-- 05.서울시 공공데이터.ipynb --
http://data.seoul.go.kr/dataList/OA-12914/A/1/datasetView.do
import requests # JSON 만 받아 올 경우 requests 면 충분하다!!!
from bs4 import BeautifulSoup # XML 을 받아 올 경우 BeautifulSoup 필요함!!
key="4d4f424377646c6439396356597354"
date = "20240301"
end_index = 20
req_type = "json"
url = f'http://openapi.seoul.go.kr:8088/{key}/{req_type}/CardSubwayStatsNew/1/{end_index}/{date}'
url
response = requests.get(url)
response
response.text
data = response.json()
data
rows = data['CardSubwayStatsNew']['row']
len(rows)
rows[0]
result = [
{
"호선" : row['LINE_NUM'],
"역명" : row['SUB_STA_NM'],
"승차 인원" : row['RIDE_PASGR_NUM'],
"하차 인원" : row['ALIGHT_PASGR_NUM'],
}
for row in rows
]
result
import pandas as pd
pd.DataFrame(result)