Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions week3大作业提交/wudi/3.5homework-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

# coding: utf-8

# In[1]:

import pymongo,time,charts


# In[2]:

client = pymongo.MongoClient('localhost',27017)
ganji = client['ganji']
the_sample2 = ganji['the_sample2']


# In[49]:

def get_area():
areas = []
for item in the_sample2.find():
areas.append(item['area'][0])
return list(set(areas))


def get_data(date1,date2,area):
pipeline = [
{'$match':{'$and':[{'area':{'$all':area}},{'pub_date':{'$gte':date1,'$lte':date2}}]}},
{'$group':{'_id':{'$slice':['$cates',2,1]},'counts':{'$sum':1}}},
{'$sort':{'counts':-1}},
{'$limit':3}
]


for x in the_sample2.aggregate(pipeline):
data ={
'name':x['_id'][0],
'data':[x['counts']],
'type':'column'#圆柱图

}

yield data



# In[50]:


series = [x for x in get_data('2015.12.15','2016.1.15',['西单'])]
options = {
'chart' : {'zoomType':'xy'},
'title' : {'text':'发帖量统计'},
'subtitle':{'text':'可视化统计图表'},
'yAxis' : {'title':{'text':'数量'}},

}

charts.plot(series,options=options,show='inline')


# In[ ]:



47 changes: 47 additions & 0 deletions week3大作业提交/wudi/3.5homework-avg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

# coding: utf-8

# In[1]:

import pymongo,charts


# In[2]:

client = pymongo.MongoClient('localhost',27017)
ganji = client['ganji']
the_sample2 = ganji['the_sample2']


# In[3]:

def get_avg(cates):
pipeline = [
{'$match':{'$and':[{'cates':cates},
{'look':{'$nin':['-']}}
]}},
{'$group':{'_id':'$look','avg':{'$avg':'$price'}}},
{'$sort':{'avg':-1}}


]

for x in the_sample2.aggregate(pipeline):
yield x['avg']


# In[4]:

data = [i for i in get_avg('北京二手手机')]
options = {
'title':{'text':'新旧-价格'},
'xAxis':{'categories':['95成新', '全新', '99成新', '9成新', '8成新', '7成新及以下', '报废机/尸体']},
'yAxis':{'title':{'text':'价格'}}
}
charts.plot(data,show='inline',options=options)


# In[ ]: