안녕하세요 정경석입니다.
아파트 시세와 급매 등을 쉽게 조회할 수 있는 앱을 소개하며
해당 서비스의 핵심 도구와
아파트 투자 인사이트 등을 소개하려고 합니다.
https://kevin-urgent-sale.streamlit.app/
Part2에서는
한정된 시간에 함께 실습할 수가 없으므로
실제 실습해 보실 수 있는 부분을 정리해 보았으니
잘 따라와주시면 좋겠습니다.
부제 : 네이버 부동산 시세 트레킹과 시각화(Part2)
목차
네이버 시세 정보 import
3.네이버 시세 정보 import
구글 계정이 있으면 구글 Colaboratory를 이용하여 네이버 시세를
elastic cloud에 보낼 수 있습니다.
3-1. 아래 링크를 누르고 “Drive 복사”를 합니다.
https://colab.research.google.com/drive/1HfN4Rg1Yy1PJ_bQXtJknJWuibfB01zks?usp=sharing
3-2. elastic cloud id와 elastic api key를 넣고 런타임의 모두실행을 선택합니다.
서울 모든 아파트 정보 수집은 3시간 정도 걸립니다.
(아.. 너무 수집 주기를 앞당기면.. 네이버에서 막아버립니다. ㅠㅠ)
3-3. 왼쪽 메뉴의 “Management > Dev Tools” 로 이동합니다.
3-4. 아파트 등록일 필드를 추가해봅니다.
코드
PUT _ingest/pipeline/my_date_conversion_pipeline
{
"description": "Converts date from 'yy.MM.dd.' format to a date field, removing trailing period",
"processors": [
{
"gsub": {
"field": "atclCfmYmd",
"pattern": "\\.",
"replacement": ""
}
},
{
"date": {
"field": "atclCfmYmd",
"target_field": "reg_date",
"formats": ["yyMMdd"],
"timezone": "UTC"
}
}
]
}
실행 예
3-5. 일부 필드를 추가를 위하여 아래 코드를 붙여넣고 실행해 봅니다.
코드
# 1단계: 새로운 인덱스 생성
PUT /naver_apt_2024
{
"mappings": {
"properties": {
"location": {
"type": "geo_point"
},
"spc1_num": {
"type": "float"
},
"spc2_num": {
"type": "float"
}
}
}
}
# 2단계 : 재색인
POST /_reindex
{
"source": {
"index": "naver_apt_basic_tmp" // 기존 인덱스명
},
"dest": {
"index": "naver_apt_2024", // 새로운 인덱스명
"pipeline": "my_date_conversion_pipeline"
},
"script": {
"source": """
if (ctx._source.spc1 != null) {
ctx._source.spc1_num = Float.parseFloat(ctx._source.spc1);
}
if (ctx._source.spc2 != null) {
ctx._source.spc2_num = Float.parseFloat(ctx._source.spc2);
}
if (ctx._source.lng != null) {
ctx._source.location = [ctx._source.lng, ctx._source.lat];
}
""",
"lang": "painless"
}
}
# 2단계 : 재색인(필드추가)
POST /_reindex?wait_for_completion=false
{
"source": {
"index": "naver_apt_basic_tmp"
},
"dest": {
"index": "naver_apt_2024",
"pipeline": "my_date_conversion_pipeline"
},
"script": {
"source": """
if (ctx._source.spc1 != null) {
ctx._source.spc1_num = Float.parseFloat(ctx._source.spc1);
}
if (ctx._source.spc2 != null) {
ctx._source.spc2_num = Float.parseFloat(ctx._source.spc2);
}
if (ctx._source.lng != null) {
ctx._source.location = [ctx._source.lng, ctx._source.lat];
}
// spc1를 숫자로 변환
if (ctx._source.spc1 != null) {
ctx._source.spc1_num = Float.parseFloat(ctx._source.spc1);
// spc2_num 기준으로 type 필드 추가
if (ctx._source.spc1_num < 66) {
ctx._source.type = "소형";
} else if (ctx._source.spc1_num >= 66 && ctx._source.spc1_num <= 99) {
ctx._source.type = "20평대";
} else if (ctx._source.spc1_num >= 99 && ctx._source.spc1_num <= 132) {
ctx._source.type = "30평대";
} else if (ctx._source.spc1_num > 132) {
ctx._source.type = "중대형";
}
}
// crawl_date 필드를 새로 추가
String originalDate = "20250121"; // 고정된 값
if (originalDate != null) {
String year = originalDate.substring(0, 4);
String month = originalDate.substring(4, 6);
String day = originalDate.substring(6, 8);
ctx._source.crawl_date = year + "-" + month + "-" + day + "T00:00:00Z";
}
""",
"lang": "painless"
}
}
실행 예
3-6. 다시 stack management> Kibana > Data view로 이동합니다.
3.7 아래 내용처럼 기입하고 “data view create”합니다.
3.8 왼쪽 메뉴 Analytics에서 Discover로 이동합니다.
3-9. view all matches를 클릭합니다.
3-10. 드디어 .. 12만개 정도의 네이버 시세 정보를 탐색하실 수 있습니다.
이제 탐색 조건과 여러 기능을 눌러보면서 네이버 시세 정보를 탐색해보세요
#9기재테크