- 學(xué)習(xí)find 函數(shù)
- 學(xué)習(xí)yield
- 學(xué)習(xí)數(shù)據(jù)清洗
- Jupyter Notebook 畫線性圖
- 結(jié)果:
for i in infos.find():
frags= i['data']
#print (frags)
if (i['data']==[]) | (i['data']=='0'):
frags = []
else:
frags= '2016-' + str(i['data'])
infos.update_one({'_id': i['_id']}, {'$set': {'data': frags}})
def get_all_dates(date1, date2):
the_date = date(int(date1.split('-')[0]),int(date1.split('-')[1]),int(date1.split('-')[2]))
end_date = date(int(date2.split('-')[0]),int(date2.split('-')[1]),int(date2.split('-')[2]))
days = timedelta(days=1)
while the_date <= end_date:
yield the_date.strftime('%Y-%m-%d')
the_date = the_date+days
def get_date_within(date1, date2, areas):
each_day_post =0
for area in areas:
area_date_post=[]
for date in get_all_dates(date1, date2):
a = list(infos.find({'data':date, 'area':area}))
#print (a)
each_day_post = len(a)
area_date_post.append(each_day_post)
data = {
'name': area,
'data': area_date_post,
'type': 'line'
}
yield data
options = {
'chart' : {'zoomType':'xy'},
'title' : {'text': '發(fā)帖量統(tǒng)計'},
'subtitle': {'text': '可視化統(tǒng)計圖表'},
'xAxis' : {'categories': [i for i in get_all_dates('2016-07-26', '2016-07-29')]},
'yAxis' : {'title': {'text': '數(shù)量'}}
}
series = [i for i in get_date_within('2016-07-26', '2016-07-29',['宣武','海淀','豐臺'])]
charts.plot(series, options=options,show='inline')
# options=dict(title=dict(text='Charts are AWESOME!!!'))
- 結(jié)果
Paste_Image.png