> ## Content Index
> Fetch the complete content index at: https://bongholee.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# [Python]지하철 승하차인원 Open API로 가지고 오기
- URL: https://bongholee.com/python-jihaceol-seunghacainweon-open-apiro-gajigo-ogi/
- Published: 2022-04-22T14:40:16.000Z
- Updated: 2022-04-22T14:40:16.000Z
- Author: Bongho Lee
- Tags: Data, Python, programming, #Import 2026-11-22 06:32

사업쪽 담당자가 Python으로 공부하다가, 종종 물어보러 온다.

오늘은 지하철 승하차인원을 엑셀로 안받고 직접 API로 가지고 오는 법 물어보길래 최소한으로 코드를 작성해주었다.

Python Crawling은 익숙치 않아서 겸사겸사 기록용으로 남긴다.

Auth는 \[서울시 데이터광장\]([https://data.seoul.go.kr/](https://data.seoul.go.kr/?ref=bongholee.com))가서 받아오면 된다.

```
import pandas as pd
import requests

result=requests.get(f'http://openapi.seoul.go.kr:8088/{Auth}/json/CardSubwayStatsNew/1/999/20220301')

data=result.json()

df = pd.DataFrame(data['CardSubwayStatsNew']['row'])
print(df.shape)
df.head()
```

(593, 6) \[22\]:

|   | USE\_DT  | LINE\_NUM | SUB\_STA\_NM | RIDE\_PASGR\_NUM | ALIGHT\_PASGR\_NUM | WORK\_DT |
| - | -------- | --------- | ------------ | ---------------- | ------------------ | -------- |
| 0 | 20220301 | 1호선       | 서울역          | 20994.0          | 19468.0            | 20220304 |
| 1 | 20220301 | 1호선       | 시청           | 12439.0          | 12379.0            | 20220304 |
| 2 | 20220301 | 1호선       | 종각           | 15750.0          | 13544.0            | 20220304 |
| 3 | 20220301 | 1호선       | 종로3가         | 16349.0          | 14533.0            | 20220304 |
| 4 | 20220301 | 1호선       | 종로5가         | 14036.0          | 13472.0            | 20220304 |