부동산 거래량
In [102]:
#-*- encoding: utf8 -*-
import os
import glob
import pandas as pd
import matplotlib.pyplot as plt
import unicodedata
In [103]:
import matplotlib
In [104]:
matplotlib.rc('font', family='AppleGothic')
In [193]:
def load_data(path):
filenames = glob.glob(os.path.join(path, '*.csv'))
ret = {}
for fname in filenames:
dft = pd.read_csv(fname)
dft.columns = dft.columns.str.normalize('NFC')
dft['거래금액(만원)'] = dft['거래금액(만원)'].str.replace(',', '')# extract('(\d+),(\d+)')
dft['거래금액(만원)'] = pd.to_numeric(dft['거래금액(만원)'])
dname = fname.split('_')[0].split('/')[-1]
ret[unicodedata.normalize('NFC', dname)] = dft
return ret
In [194]:
df_dict = load_data('./trade/')
In [195]:
df_dict['서울'].head(3)
Out[195]:
In [117]:
def cal_volume(data_dict):
data = {}
for key, dft in data_dict.items():
data[key] = dft.groupby('계약년월').count()['시군구']
df_count = pd.DataFrame(data)
df_count.index = pd.to_datetime(df_count.index, format='%Y%m')
return df_count
In [181]:
def cal_mean(data_dict):
data = {}
for key, dft in data_dict.items():
# print(key)
data[key] = dft[['계약년월', '거래금액(만원)']].groupby('계약년월').mean()['거래금액(만원)']
# print(data)
df_mean = pd.DataFrame(data)
df_mean.index = pd.to_datetime(df_count.index, format='%Y%m')
return df_mean
In [182]:
dfm = cal_mean(df_dict)
In [183]:
dfm
Out[183]:
In [191]:
dfm2 = dfm / dfm.iloc[0]
dfm2.plot(figsize=(15,8), title='평균 거래 금액')
Out[191]:
In [188]:
df_count = cal_volume(df_dict)
In [192]:
df_count_nor = df_count / df_count.iloc[0]
df_count_nor.plot(figsize=(15,8), title='거래량')
Out[192]:
'Machine Learning(머신러닝)' 카테고리의 다른 글
부동산 거래량 ( ~ 19.5월) (0) | 2019.06.26 |
---|---|
부동산 거래량 (~2019년 03월) (0) | 2019.04.07 |
Python을 이용한 인스타그램 태그 크롤링 (5) | 2019.03.16 |
강 인공지능과 약 인공지능 (0) | 2018.09.17 |
Machine learning을 포함한 A.I 구조 (0) | 2018.09.10 |