Python - Jupyter Notebook 畫線性圖-7日內(nèi)每個區(qū)域發(fā)帖量統(tǒng)計

  1. 學(xué)習(xí)find 函數(shù)
  2. 學(xué)習(xí)yield
  3. 學(xué)習(xí)數(shù)據(jù)清洗
  4. Jupyter Notebook 畫線性圖
  5. 結(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!!!'))
  1. 結(jié)果
Paste_Image.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容