diff --git a/PriceSystem/sell_price/zhuge0118A.py b/PriceSystem/sell_price/zhuge0118A.py index 3ba7dba..c977e83 100644 --- a/PriceSystem/sell_price/zhuge0118A.py +++ b/PriceSystem/sell_price/zhuge0118A.py @@ -51,28 +51,7 @@ dsfjujia_time = front_step_time(430) // 100 # 存到数据库的日期 -""" -def weekend00(): - today = datetime.datetime.now() - now_time=datetime.datetime(today.year, today.month, today.day, 0, 0, 0) - week_time = now_time.weekday() - - - if week_time>=4: - future_time = now_time-datetime.timedelta(days=week_time+1-7) - d1= future_time.strftime('%Y%m%d') - weekend1= datetime.datetime.strptime(d1,'%Y%m%d') - weekend=weekend1+datetime.timedelta(hours=-8) - return weekend - else: - future_time = now_time-datetime.timedelta(days=week_time+1) - d1= future_time.strftime('%Y%m%d') - weekend1= datetime.datetime.strptime(d1,'%Y%m%d') - weekend=weekend1+datetime.timedelta(hours=-8) - return weekend - -""" # date="2018-02-04" ############################################################ @@ -823,7 +802,8 @@ def commonprice(ct, rl, p): al = [ 'lianjia_esf_price', 'zhugezhaofang_esf_price', - 'fanggugu_esf_price' + 'fanggugu_esf_price', + 'yungujia_esf_price' ] bl = ['anjuke_esf_price', 'soufang_esf_price', @@ -963,7 +943,7 @@ def commonprice(ct, rl, p): elif data.shape[0] > 0: print('诸葛找房算法') - from zhuge import zhuge_consist + #from zhuge import zhuge_consist data['avg'] = data['total_price'] / data['area'] @timer def guolv_data11(data, neighb): @@ -976,35 +956,59 @@ def commonprice(ct, rl, p): return data ddd11 = guolv_data11(data, neighb[0]) + + #print('ddd11=',ddd11) if ddd11.shape[0] > 2: - s = zhuge_consist.url_lable(ddd11) - s1 = zhuge_consist.drop_rubbish(s) + #s = zhuge_consist.url_lable(ddd11) + #s1 = zhuge_consist.drop_rubbish(s) # print('s1=',s1) - s2 = set(s1) + #s2 = set(s1) # print('s2=',s2) - if len(s2) > 3: + if ddd11.shape[0] > 3: from zhuge import zhuge_consist - s = zhuge_consist.zhuge_out(ddd11) + s = zhuge_consist.zhuge_out(ddd11,3,1) + + #print('s=',s) def compelex(ddd11, s, neighb, junjia): - cc1 = ddd11['avg'].dropna() - - kmzhuge = k_means(cc1) + #cc1 = ddd11['avg'].dropna() + + #print('cc1=',cc1) + kmzhuge = zhuge_consist.zhuge_out(ddd11,3,0) junjia['zhuge_logic'] = s junjia['kmzg'] = kmzhuge if type(neighb) != str and (neighb) != None: junjia['neighb'] = neighb - # print('junjia',junjia) + #print('junjia',junjia) junjia_front = junjia[['zhuge_logic', 'kmzg']] - cc = group(junjia_front, junjia, 1) + + def drop_ganji(junjia): + a={'ganji_esf_price','anjuke_esf_price'} + #print('a=',a) + b=set(list(junjia.index)) + #print('b=',b) + c=a & b + + #print('c=',c) + if len(c)==2: + #print('o'*100) + return junjia.drop('ganji_esf_price') + else: + return junjia + + + junjia1=drop_ganji(junjia) + + #print('junjia_ganji=',junjia1,'$'*100) + cc = group(junjia_front, junjia1, 1) # junjia_km=k_means(junjia) # print('cc=',cc) ############ @@ -1259,6 +1263,8 @@ def out_put_price(ct, rl, lk, weekend): lf = add_alias(lf) p = ghhh(lf[['name', 'alias', 'estate_type2']])[0] + + print('p=',p) mm = commonprice(ct, rl, p) diff --git a/PriceSystem/test.py b/PriceSystem/test.py index 72af330..4f3c502 100644 --- a/PriceSystem/test.py +++ b/PriceSystem/test.py @@ -5,9 +5,12 @@ import sell_price.zhuge0118A as sellPrice s = time.time() -ct = '上海' -rl = '嘉定' -lk = '莱茵北郡' +#上海嘉定莱茵北郡 +ct='上海' +rl='嘉定' +lk='莱茵北郡别墅' + +#上海闵行上海康城 weekend = datetime.datetime.strptime("2018-03-11", "%Y-%m-%d") sellPrice.out_put_price(ct, rl, lk, weekend) @@ -16,3 +19,5 @@ sellPrice.out_put_price(ct, rl, lk, weekend) e = time.time() print(e - s) + + diff --git a/PriceSystem/zhuge/__init__.py b/PriceSystem/zhuge/__init__.py index 4d78a3e..e52b25c 100644 --- a/PriceSystem/zhuge/__init__.py +++ b/PriceSystem/zhuge/__init__.py @@ -1 +1 @@ -from zhuge import zhuge2 \ No newline at end of file +from zhuge import zhuge_consist \ No newline at end of file diff --git a/PriceSystem/zhuge/zhuge2.py b/PriceSystem/zhuge/zhuge2.py deleted file mode 100644 index ec61f18..0000000 --- a/PriceSystem/zhuge/zhuge2.py +++ /dev/null @@ -1,487 +0,0 @@ -# -*- coding: utf-8 -*- -""" -Created on Tue Nov 28 13:15:49 2017 - -@author: Administrator -""" -import pymongo -import pandas -from collections import Counter -import numpy -import collections -import re - -def url_lable(dmi1): - - company_list=['lianjia','zhuge','5i5j','iwjw','fangdd','centanet', - 'cityhouse','esf','baixing','ganji','anjuke','58'] - - for p in company_list: - #print('p=',p) - for k in dmi1.index: - #print('k=',k) - #print(dmi1['url'][k]) - ff=dmi1['url'][k] - if type(ff)==str: - - if p in dmi1['url'][k]: - dmi1.loc[k,'url']=p - return dmi1 - - -def drop_rubbish(dd1): - - for i in dd1.index: - pp=dd1['url'][i] - - # print(pp) - - if type(pp)==str: - - if len(pp)>12 : - dd1=dd1.drop(i) - return dd1 - - -#dd=drop_rubbish(dd1) - - - -def zhuge_out(ddd): - - #print('我在诸葛文件内',ddd) - - - def url_lable(company_list,dmi1): - - for p in company_list: - #print('p=',p) - for k in dmi1.index: - #print('k=',k) - #print(dmi1['url'][k]) - ff=dmi1['url'][k] - if type(ff)==str: - - if p in dmi1['url'][k]: - dmi1['url'][k]=p - return dmi1 - - def drop_rubbish(dd1): - - for i in dd1.index: - pp=dd1['url'][i] - - # print(pp) - - if type(pp)==str: - - if len(pp)>12 : - dd1=dd1.drop(i) - return dd1 - - - - - - def k_means(pp,clus): - from sklearn.cluster import KMeans - pv=list(pp) - if len(set(pv))>3: - gf=numpy.array([pv]).T - estimator = KMeans(n_clusters=clus)#构造聚类器 - estimator.fit(gf)#聚类 - label_pred = estimator.labels_ #获取聚类标签 - - aa=collections.Counter(label_pred) - - #print('aa=',aa) - v=pandas.Series(aa) - gg=list(v) - index_max=gg.index(max(gg)) - - centroids = estimator.cluster_centers_ #获取聚类中心 - #inertia = estimator.inertia_ # 获取聚类准则的总和 - center=centroids[index_max][0] - return int(center) - else: - return int(pp.mean()) - - def spilit_number_from_string(dd): - - for pl in dd.index: - bte=dd['build_date'][pl] - if bte!=None: - dd['build_date'][pl]=re.sub("\D", "", str(bte)) - - most_build=Counter(dd['build_date']).most_common(1) - dd['build_date']=dd['build_date'].fillna(most_build[0][0]) - - return dd[dd['build_date']==most_build[0][0]] - - def lower_dimention(dd): - - url_set=list( set(dd['url']) ) - - url_price=pandas.Series() - - index_list=[] - for i in url_set: - dd1=dd[dd['url']==i] - if dd1.shape[0]<=2: - index_list.extend(list(dd1.index)) - else: - most_price=k_means(dd1['total_price'],3)*1.0 - - url_price[i]=round(most_price,2) - - for j in index_list: - url_price[dd['url'][j]]=dd['total_price'][j] - - return url_price - - - def k_means_ratio(pp,clus): - from sklearn.cluster import KMeans - pv=list(pp) - if len(set(pv))>3: - gf=numpy.array([pv]).T - estimator = KMeans(n_clusters=clus)#构造聚类器 - estimator.fit(gf)#聚类 - label_pred = estimator.labels_ #获取聚类标签 - - aa=collections.Counter(label_pred) - - #print('aa=',aa) - v=pandas.Series(aa) - v=v.sort_values(ascending=False) - - ratio=v.iloc[0]/v.iloc[1] - - return round(ratio,2) - else: - return 1 - - - def popo(dmi,columns): - - most=Counter(dmi[columns]).most_common(1) - #print(dmi) - dmi2=dmi[dmi[columns]==most[0][0]] - #print('dmi2=',dmi2) - - dmiy=lower_dimention(dmi2) - #print(dmiy) - ratio2=(dmiy.max()-dmiy.min())/dmiy.mean() - ww1=round(k_means( dmiy ,3 ),2) - ww2=round(k_means(dmi2['area'].dropna(),3),2) - ww3=round(k_means(dmi2['room'].dropna(),3),2) - ww4=list(dmiy.index) - - #ww5=round(k_means_ratio(dmi['total_price'].dropna(),3),2) - ww5=round(k_means_ratio(dmiy,3),2) - #print('dmi2=',dmi2) - - if (ratio2<0.15 and len(dmiy)>1) or (ratio2>1.2 and len(dmiy)>1) : - - return [round(ww1,2),round(ww2,2),round(ww3,2),round(100,2),ww4,ww5] - - #print('area_filter',dd) - """ - else: - return [round(ww1,2),round(ww2,2),round(ww3,2),round(len(dmiy),2),ww4,ww5] - """ - - - - - def room_define(dd,j): - - pdd=numpy.array([[None,None,None,None,None,None], - [None,None,None,None,None,None], - [None,None,None,None,None,None]]) - - - d4=dd[dd['room']==j] - - #print('room=',j,'的样本个数为',d4.shape[0]) - - pdd[0]=popo(d4,'room') - - most_area=Counter(d4['area']).most_common(1) - - - - if most_area[0][1]>=2: - - d4area=d4[d4['area']==most_area[0][0]] - - pdd[1]=popo(d4area,'area') - - most_floor=Counter(d4area['floor']).most_common(1) - - if most_floor[0][1]>=2: - d4floor=d4area[d4area['floor']==most_floor[0][0]] - #print('d4floor=',d4floor) - pdd[2]=popo(d4floor,'floor') - - return ( pdd ) - - - def dout(room_pair,dd): - - bbb=[] - #print('room_pair=',room_pair) - #print('dd=',dd) - for j in room_pair.index: - - kgg=pandas.DataFrame(room_define(dd,j), - columns=['total_price','area','room','credit','url_list','choose_index']) - kgg['avg_price']=kgg['total_price']/kgg['area'] - - #print('kgg=',kgg) - - bbb.append(kgg) - return bbb - - - - - - - - def dsf_average_price(ct,rl,lk,timd,timm): - - client = pymongo.MongoClient('192.168.0.136',27017) #'192.168.0.65',27777 - db = client.fangjia - seawater = db.average_statistics - - timd1=timd//100 - timm1=timm//100 - - query = {"city":ct,"region":rl, - "name":{"$in":lk}, - "s_date":{"$gt":timd1,"$lt":timm1}} - #lt= seawater.count(query) - #print(lt) - pos = list(seawater.find(query).limit(3000)) - - data=pandas.DataFrame(pos) - del pos - return data - - - dsf_name_list={'soufang_new_price','soufang_esf_price', - 'anjuke_new_price','anjuke_esf_price', - 'sina_new_price','sina_esf_price', - 'ganji_esf_price','cric_new_price', - 'cric_esf_price', - 'lianjia_esf_price','zhugezhaofang_esf_price' - - 'fanggugu_esf_price','yungujia_esf_price' - } - - - - - - - company_list=['lianjia','zhuge','5i5j','iwjw','fangdd','centanet', - 'cityhouse','esf','baixing','ganji','anjuke','58'] - - company_name=['链家','诸葛找房','我爱我家','爱屋吉屋','房多多','中原', - '城市房产','二手房','百姓','赶集','安居客','58同城'] - company_values=[10, 10, 5, 5, 3, 2, - 1 , 1, 1, 1, 1, 1] - - #companypp=[] - import numpy as np - - a=np.array([company_name,company_values]) - - company_pandas=pandas.DataFrame(a.T,columns=['name','values'],index=company_list) - name_pair=pandas.Series(company_list,index=company_name) - - - def add_floor(ppd): - if 'floor' not in ppd.columns: - ppd['floor']= 6 - return ppd - - #ddd=url_lable(company_list,ddd) - - - - def opfm(ddo,fm): - - floor_column=ddo[fm].dropna() - if len(floor_column)>0: - - #print('floor_column=',floor_column) - most_floor=Counter(floor_column).most_common(1) - #print('floor=',ddo['floor']) - ddo[fm]=ddo[fm].fillna(most_floor[0][0]) - return ddo - else: - ddo[fm]=ddo[fm].fillna(2) - return ddo - - - - - - - def export_pp(ddd): - - ddo=ddd - #ddo=ddo.drop(0) - #print('ddo=',ddo) - ddo=add_floor(ddo) - #print('ddo=',ddo) - - if ddo.shape[0]>1: - - - ddo=opfm(ddo,'floor') - ddo=opfm(ddo,'room') - - """ - floor_column=ddo['floor'].dropna() - print('floor_column=',floor_column) - most_floor=Counter(floor_column).most_common(1) - print('floor=',ddo['floor']) - ddo['floor']=ddo['floor'].fillna(most_floor[0][0]) - - room_column=ddo['room'].dropna() - most_room=Counter(room_column).most_common(1) - ddo['room']=ddo['room'].fillna(most_room[0][0]) - """ - - ddo['area']=(ddo['area']//2)*2+1 - - #dd1=url_lable(company_list,ddo) - - #dd=drop_rubbish(dd1) - - #print(Counter(dd['url'])) - dd=ddo - mr=Counter(dd['room']) - room_pair=pandas.Series(mr) - room_pair1=room_pair.sort_values(ascending=False) - room_pair=room_pair1.iloc[:3] - opt=dout(room_pair,dd) - return opt - else: - return pandas.DataFrame() - - opt=export_pp(ddd) - - #print('opt=',opt) - - def k_means22(pp,clus): - from sklearn.cluster import KMeans - pv=list(pp) - if len(set(pv))>1: - gf=numpy.array([pv]).T - estimator = KMeans(n_clusters=clus)#构造聚类器 - estimator.fit(gf)#聚类 - label_pred = estimator.labels_ #获取聚类标签 - - aa=collections.Counter(label_pred) - - #print('aa=',aa) - v=pandas.Series(aa) - gg=list(v) - index_max=gg.index(max(gg)) - - centroids = estimator.cluster_centers_ #获取聚类中心 - #inertia = estimator.inertia_ # 获取聚类准则的总和 - center=centroids[index_max][0] - return round(center,2) - else: - return pp.mean() - - - def out_put_price(opt): - - re = pandas.concat(opt) - - #print(re) - - oo=re[re['credit']==100] - oo1=re.dropna() - - #print(oo) - if oo.shape[0]>1: - return round(k_means22( oo['avg_price'] ,2 ),2) - elif oo1.shape[0]>0: - - re1=re.sort_values(by='credit',ascending=False) - re2=re1.sort_values(by='choose_index',ascending=False) - #print(re2) - #print('#'*20) - return (re2['avg_price'].iloc[0]) - else: - #print(ddd['avg'].dropna()) - kkm=k_means(ddd['avg'].dropna(),2) - return kkm - - return int(out_put_price(opt)) - -#ddd=pandas.read_excel('ddd11.xls') - -#df=zhuge_out(ddd) -""" -ct='上海' -rl='崇明' -lk=['风伟四村'] - - -timd=20170301 -timm=20171205 - - - -def some_district_information(ct,rl,lk,timd,timm): - client = pymongo.MongoClient('192.168.0.105',27777) #'192.168.0.65',27777 - db = client.fangjia - seawater = db.seawater - seawater.find_one() - query = {"city":ct,"cat":"sell","region":rl, - "district_name":{"$in":lk}, - "p_date":{"$gt":timd,"$lt":timm}} - lt= seawater.count(query) - #print(lt) - pos = list(seawater.find(query).limit(lt)) - - data=pandas.DataFrame(pos) - del pos - return data - -ddd=some_district_information(ct,rl,lk,timd,timm) - - - -df=zhuge_out(ddd) -""" - - - - - - - - - - - - - - - - - - - - - - diff --git a/PriceSystem/zhuge/zhuge_consist.py b/PriceSystem/zhuge/zhuge_consist.py index a7cf123..26ead0d 100644 --- a/PriceSystem/zhuge/zhuge_consist.py +++ b/PriceSystem/zhuge/zhuge_consist.py @@ -4,389 +4,74 @@ Created on Tue Nov 28 13:15:49 2017 @author: Administrator """ -import pymongo +#import pymongo import pandas from collections import Counter import numpy import collections -import re -from fangjia import timer +#import re +#import time +from sklearn.cluster import KMeans +def zhuge_out(ddd,clus,rank): + + p1=ddd['total_price']/ddd['area'] + pp=p1.dropna() + + pv=list(pp) + if len(set(pv))>clus: + gf=numpy.array([pv]).T + estimator = KMeans(n_clusters=clus)#构造聚类器 + estimator.fit(gf)#聚类 + label_pred = estimator.labels_ #获取聚类标签 + + aa=collections.Counter(label_pred) + + #print('aa=',aa) + v=pandas.Series(aa) + + gg=list(v) + #print('gg=',gg) + #index_max=gg.index(max(gg)) + + centroids = estimator.cluster_centers_ #获取聚类中心 + + kk=centroids.flatten() + + jj=pandas.Series(kk,index=gg) + jj1=jj.sort_index(ascending=False) + #print(jj1) + #inertia = estimator.inertia_ # 获取聚类准则的总和 + #center=centroids[index_max][0] + #return int(center) + return jj1.iloc[rank] + else: + return int(pp.mean()) -def url_to_root(url): - if type(url) != "str": - return url - company_list = ['lianjia', 'zhuge', '5i5j', 'iwjw', 'fangdd', 'centanet', 'cityhouse', 'baixing', 'ganji', - 'anjuke', '58.com'] - for c in company_list: - if c in url: - return c - return url -@timer -def url_lable(dmi1): - house_list = dmi1.to_dict('records') - for h in house_list: - h["url"] = url_to_root(h["url"]) - dmi1 = pandas.DataFrame(house_list) - return dmi1 -def drop_rubbish(dd1): - for i in dd1.index: - pp = dd1['url'][i] - # print(pp) - if type(pp) == str: - if len(pp) > 12: - dd1 = dd1.drop(i) - return dd1 -# dd=drop_rubbish(dd1) -@timer -def zhuge_out(ddd): - # print('我在诸葛文件内',ddd) - def k_means(pp, clus): - from sklearn.cluster import KMeans - pv = list(pp) - if len(set(pv)) > clus: - gf = numpy.array([pv]).T - estimator = KMeans(n_clusters=clus) # 构造聚类器 - estimator.fit(gf) # 聚类 - label_pred = estimator.labels_ # 获取聚类标签 - aa = collections.Counter(label_pred) - # print('aa=',aa) - v = pandas.Series(aa) - gg = list(v) - index_max = gg.index(max(gg)) - centroids = estimator.cluster_centers_ # 获取聚类中心 - # inertia = estimator.inertia_ # 获取聚类准则的总和 - center = centroids[index_max][0] - return int(center) - else: - return int(pp.mean()) - def spilit_number_from_string(dd): - for pl in dd.index: - bte = dd['build_date'][pl] - if bte != None: - dd['build_date'][pl] = re.sub("\D", "", str(bte)) - most_build = Counter(dd['build_date']).most_common(1) - dd['build_date'] = dd['build_date'].fillna(most_build[0][0]) - - return dd[dd['build_date'] == most_build[0][0]] - - def lower_dimention(dd): - - url_set = list(set(dd['url'])) - - url_price = pandas.Series() - - index_list = [] - for i in url_set: - dd1 = dd[dd['url'] == i] - if dd1.shape[0] <= 2: - index_list.extend(list(dd1.index)) - else: - most_price = k_means(dd1['total_price'], 3) * 1.0 - - url_price[i] = round(most_price, 2) - - for j in index_list: - url_price[dd['url'][j]] = dd['total_price'][j] - - return url_price - - def k_means_ratio(pp, clus): - from sklearn.cluster import KMeans - pv = list(pp) - if len(set(pv)) > 3: - gf = numpy.array([pv]).T - estimator = KMeans(n_clusters=clus) # 构造聚类器 - estimator.fit(gf) # 聚类 - label_pred = estimator.labels_ # 获取聚类标签 - - aa = collections.Counter(label_pred) - - # print('aa=',aa) - v = pandas.Series(aa) - v = v.sort_values(ascending=False) - - ratio = v.iloc[0] / v.iloc[1] - - return round(ratio, 2) - else: - return 1 - - def popo(dmi, columns): - - most = Counter(dmi[columns]).most_common(1) - # print(dmi) - dmi2 = dmi[dmi[columns] == most[0][0]] - # print('dmi2=',dmi2) - - dmiy = lower_dimention(dmi2) - # print(dmiy) - ratio2 = (dmiy.max() - dmiy.min()) / dmiy.mean() - ww1 = round(k_means(dmiy, 3), 2) - ww2 = round(k_means(dmi2['area'].dropna(), 3), 2) - ww3 = round(k_means(dmi2['room'].dropna(), 3), 2) - ww4 = list(dmiy.index) - - # ww5=round(k_means_ratio(dmi['total_price'].dropna(),3),2) - ww5 = round(k_means_ratio(dmiy, 3), 2) - # print('dmi2=',dmi2) - - if (ratio2 < 0.15 and len(dmiy) > 1) or (ratio2 > 1.2 and len(dmiy) > 1): - return [round(ww1, 2), round(ww2, 2), round(ww3, 2), round(100, 2), ww4, ww5] - - # print('area_filter',dd) - """ - else: - return [round(ww1,2),round(ww2,2),round(ww3,2),round(len(dmiy),2),ww4,ww5] - """ - - def room_define(dd, j): - - pdd = numpy.array([[None, None, None, None, None, None], - [None, None, None, None, None, None], - [None, None, None, None, None, None]]) - - d4 = dd[dd['room'] == j] - - # print('room=',j,'的样本个数为',d4.shape[0]) - - pdd[0] = popo(d4, 'room') - - most_area = Counter(d4['area']).most_common(1) - - if most_area[0][1] >= 2: - - d4area = d4[d4['area'] == most_area[0][0]] - - pdd[1] = popo(d4area, 'area') - - most_floor = Counter(d4area['floor']).most_common(1) - - if most_floor[0][1] >= 2: - d4floor = d4area[d4area['floor'] == most_floor[0][0]] - # print('d4floor=',d4floor) - pdd[2] = popo(d4floor, 'floor') - - return (pdd) - - def dout(room_pair, dd): - - bbb = [] - # print('room_pair=',room_pair) - # print('dd=',dd) - for j in room_pair.index: - kgg = pandas.DataFrame(room_define(dd, j), - columns=['total_price', 'area', 'room', 'credit', 'url_list', 'choose_index']) - kgg['avg_price'] = kgg['total_price'] / kgg['area'] - - # print('kgg=',kgg) - - bbb.append(kgg) - return bbb - - def dsf_average_price(ct, rl, lk, timd, timm): - - client = pymongo.MongoClient('192.168.0.136', 27017) # '192.168.0.65',27777 - db = client.fangjia - seawater = db.average_statistics - - timd1 = timd // 100 - timm1 = timm // 100 - - query = {"city": ct, "region": rl, - "name": {"$in": lk}, - "s_date": {"$gt": timd1, "$lt": timm1}} - # lt= seawater.count(query) - # print(lt) - pos = list(seawater.find(query).limit(3000)) - - data = pandas.DataFrame(pos) - del pos - return data - - dsf_name_list = {'soufang_new_price', 'soufang_esf_price', - 'anjuke_new_price', 'anjuke_esf_price', - 'sina_new_price', 'sina_esf_price', - 'ganji_esf_price', 'cric_new_price', - 'cric_esf_price', - 'lianjia_esf_price', 'zhugezhaofang_esf_price' - - 'fanggugu_esf_price', 'yungujia_esf_price' - } - - company_list = ['lianjia', 'zhuge', '5i5j', 'iwjw', 'fangdd', 'centanet', - 'cityhouse', 'baixing', 'ganji', 'anjuke', '58'] - - company_name = ['链家', '诸葛找房', '我爱我家', '爱屋吉屋', '房多多', '中原', - '城市房产', '百姓', '赶集', '安居客', '58同城'] - company_values = [10, 10, 5, 5, 3, 2, - 1, 1, 1, 1, 1] - - # companypp=[] - import numpy as np - - a = np.array([company_name, company_values]) - - company_pandas = pandas.DataFrame(a.T, columns=['name', 'values'], index=company_list) - name_pair = pandas.Series(company_list, index=company_name) - - def add_floor(ppd): - if 'floor' not in ppd.columns: - ppd['floor'] = 6 - return ppd - - # ddd=url_lable(company_list,ddd) - - @timer - def opfm(ddo, fm): - - floor_column = ddo[fm].dropna() - if len(floor_column) > 0: - - # print('floor_column=',floor_column) - most_floor = Counter(floor_column).most_common(1) - # print('floor=',ddo['floor']) - ddo[fm] = ddo[fm].fillna(most_floor[0][0]) - return ddo - else: - ddo[fm] = ddo[fm].fillna(2) - return ddo - - @timer - def export_pp(ddd): - - ddo = ddd - # ddo=ddo.drop(0) - # print('ddo=',ddo) - ddo = add_floor(ddo) - # print('ddo=',ddo) - - if ddo.shape[0] > 1: - - ddo = opfm(ddo, 'floor') - ddo = opfm(ddo, 'room') - - ddo['area'] = (ddo['area'] // 2) * 2 + 1 - - # dd1=url_lable(company_list,ddo) - - # dd=drop_rubbish(dd1) - - # print(Counter(dd['url'])) - dd = ddo - mr = Counter(dd['room']) - room_pair = pandas.Series(mr) - room_pair1 = room_pair.sort_values(ascending=False) - room_pair = room_pair1.iloc[:3] - opt = dout(room_pair, dd) - return opt - else: - return pandas.DataFrame() - - opt = export_pp(ddd) - - # print('opt=',opt) - - def k_means22(pp, clus): - from sklearn.cluster import KMeans - pv = list(pp) - if len(set(pv)) > 1: - gf = numpy.array([pv]).T - estimator = KMeans(n_clusters=clus) # 构造聚类器 - estimator.fit(gf) # 聚类 - label_pred = estimator.labels_ # 获取聚类标签 - - aa = collections.Counter(label_pred) - - # print('aa=',aa) - v = pandas.Series(aa) - gg = list(v) - index_max = gg.index(max(gg)) - - centroids = estimator.cluster_centers_ # 获取聚类中心 - # inertia = estimator.inertia_ # 获取聚类准则的总和 - center = centroids[index_max][0] - return round(center, 2) - else: - return pp.mean() - - def out_put_price(opt): - - re = pandas.concat(opt) - - # print(re) - - oo = re[re['credit'] == 100] - oo1 = re.dropna() - - # print(oo) - if oo.shape[0] > 1: - return round(k_means22(oo['avg_price'], 2), 2) - elif oo1.shape[0] > 0: - - re1 = re.sort_values(by='credit', ascending=False) - re2 = re1.sort_values(by='choose_index', ascending=False) - # print(re2) - # print('#'*20) - return (re2['avg_price'].iloc[0]) - else: - # print(ddd['avg'].dropna()) - kkm = k_means(ddd['avg'].dropna(), 2) - return kkm - - return int(out_put_price(opt)) - - -""" -ct='上海' -rl='崇明' -lk=['风伟四村'] - - -timd=20170301 -timm=20171205 - - - -def some_district_information(ct,rl,lk,timd,timm): - client = pymongo.MongoClient('192.168.0.105',27777) #'192.168.0.65',27777 - db = client.fangjia - seawater = db.seawater - seawater.find_one() - query = {"city":ct,"cat":"sell","region":rl, - "district_name":{"$in":lk}, - "p_date":{"$gt":timd,"$lt":timm}} - lt= seawater.count(query) - #print(lt) - pos = list(seawater.find(query).limit(lt)) - data=pandas.DataFrame(pos) - del pos - return data - -ddd=some_district_information(ct,rl,lk,timd,timm) -df=zhuge_out(ddd) -""" + + +