fjw计算均价

# -*- coding: utf-8 -*-
"""
Created on Thu Aug 24 15:14:07 2017

@author: Administrator
"""

import pymongo
from pymongo import MongoClient
import numpy as np
import pandas as  pd
from pandas import DataFrame,Series
from numpy import row_stack,column_stack
from dateutil.parser import parse
from matplotlib.pylab import date2num
import random

#导入经度和纬度,把经纬度转化成DataFrame

client1 = MongoClient('192.168.0.136',27017)
db1 = client1.fangjia
seaweed1 = db1.seaweed

#print(seaweed.find_one({"city":"上海","region":"浦东","name":"康桥半岛二期"},{"lat2":1,"lng2":1}))

cy_rg=["成都","锦江"]



query1 = {"status":0,"cat":"district","city":cy_rg[0],"region":cy_rg[1]}
fields1 = {"lat2":1,"lng2":1, "city":1,"region":1,"cat":1,"name":1}

lct= list()
for s in seaweed1.find(query1, fields1):
    lct.append(s)

lf=DataFrame(lct)

lk=list(lf['name'])


#从公司的数据库中导入数据
client = MongoClient('192.168.10.88',27777)
db = client.fangjia
seawater = db.seawater
seawater.find_one()

# 索引数据库里的数据

for i in range(len(lk)):
    query = {"city":cy_rg[0],"cat":"sell","region":cy_rg[1],
             "district_name":lk[i],"p_date":{"$gt":20170701}}
    lt= seawater.count(query)
    #print(lt)
    pos = list()
    for s in seawater.find(query).limit(lt):
        pos.append(s)

    data=DataFrame(pos)

    if data.shape[0]>3:
        ppd=data[['total_price','area','district_name']]
        ppd1=ppd.dropna()

        avv=ppd['total_price']/ppd['area']
        #suma=ppd1['area'].values.sum()
        avp=int(avv.mean())



        print(avp,ppd1['district_name'][1])



        client1 = MongoClient('192.168.0.136',27017)
        db1 = client1.fangjia_stat
        stat = db1.district_stat
        stat.save({"city":cy_rg[0],"region":cy_rg[1],"district_name":ppd1['district_name'][1],
           "avg_price":avp, "weeedend":"2017-09-08"})

posted @ 2022-08-19 22:59  luoganttcc  阅读(24)  评论(0编辑  收藏  举报