Python - Jupyter Notebook 画线性图-7

2016-07-31  本文已影响0人  rdczowh
  1. 学习find 函数
  2. 学习yield
  3. 学习数据清洗
  4. Jupyter Notebook 画线性图
  5. 结果:
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': '发帖量统计'},
    'subtitle': {'text': '可视化统计图表'},
    'xAxis'   : {'categories': [i for i in get_all_dates('2016-07-26', '2016-07-29')]},
    'yAxis'   : {'title': {'text': '数量'}}
    }

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. 结果
Paste_Image.png
上一篇 下一篇

猜你喜欢

热点阅读