-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubway.py
More file actions
30 lines (25 loc) · 853 Bytes
/
subway.py
File metadata and controls
30 lines (25 loc) · 853 Bytes
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
import pandas as pd
from pymongo import MongoClient
from datetime import datetime
# CSV 파일 경로
csv_file = 'subway_data.csv'
# MongoDB 연결 정보
client = MongoClient('mongodb://localhost:27017/')
db = client['Project']
collection = db['subway']
# CSV 파일 읽기
data = pd.read_csv(csv_file)
# 데이터를 JSON 형식으로 변환하여 MongoDB에 삽입
for _, row in data.iterrows():
record = {
'date': datetime.strptime(str(row['사용일자']), '%Y%m%d'),
'location': {
'line': row['노선명'],
'station': row['역명']
},
'boarding': row['승차총승객수'],
'alighting': row['하차총승객수'],
'registration_date': datetime.strptime(str(row['등록일자']), '%Y%m%d')
}
collection.insert_one(record)
print("Data inserted successfully.")