charts1

将前面爬虫所得数据进行一个简单的分析

  1. 使用charts进行展示,charts是highchats的一个与python有关的库,但注意在官网下的可能不能用,需要替换文件。
    简单用法:charts.plot(series,show = ’inline‘,options)
    series格式为一个列表,里面是字典,如
    series = [{'name': 'John','data': [5],'type': 'column'},{'name': 'John','data': [5],'type': 'column'}],里面的key为 name,data,type.
    show表示在该网页内显示,options可以设置标题啥的。
  2. 采用了生成器来生成series所需的数据格式
  3. 前面进行数据的筛选,合并。
import pymongo,charts

client = pymongo.MongoClient('localhost',27017)
tongcheng = client['tongcheng']
info_list = tongcheng.info_list


area_list = []
area_index = []
area_count = []

for i in info_list.find():
    if i['area'].startswith('北京'):
        area_list.append(i['area'][-2:])

area_index = list(set(area_list))
for area in area_index:
    area_count.append(area_list.count(area))

#print(area_index)

def gen_data(types):
    length = 0
    if length <= len(area_index):
        for area,times in zip(area_index,area_count):
            data ={
                'name':area,
                'data':[times],
                'type':types
            }
            yield data
            length += 1

series = [data for data in gen_data('column')]
charts.plot(series,show = 'inline',options = dict(title=dict(text='北京交易')))
chart.jpeg
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容