python fine函数_Python实战计划——第三周第三节:使用find函数精确查找数据

视频重点

练习代码

扩展

1. 视频重点

from datetime imort timedelta,date处理日期。第一步:统一日期格式。第二步:转换数据。

for i in item_info.find():

frags = i['pub_date'].split('-')

if len(frags) == 1:

date = frags[0]

else:

date = '{}.{}.{}'.format(frags[0],frags[1],frags[2])

item_info.update_one({'_id':i['_id']},{'$set':{'pub_date':date}})

用两个for循环来实现每一x坐标上的y轴数据

def get_data_within(date1,date2,areas):

for area in areas: #每一地区下(对应不同折线)

area_day_posts = []

for date in get_all_dates(date1,date2):#x轴的数据,两个日期间的每一个日期

a = list(item_info.find({'pub_date':date,'area':area}))#将两个for迭代出的数据,作为find参数,找到数据

each_day_post = len(a)#统计数据个数,即y轴发帖量

area_day_posts.append(each_day_post)

data = {

'name': area,

'data': area_day_posts,#与上次的柱状体不同,是描述name的一组数据

'type': 'line'

}

yield data

charts图表中折线图,option的含义

charts.plot(series, options=options,show='inline')options时plot方法的参数之一,定义

options = {

'chart' : {'zoomType':'xy'},

'title' : {'text': '发帖量统计'},

'subtitle': {'text': '可视化统计图表'},

'xAxis' : {'categories': [i for i in get_all_dates('2015.12.24','2016.01.05')]},

'yAxis' : {'title': {'text': '数量'}}

}

作为plot方法的传递参数

2. 练习代码

c98ad028ff6d

3-3homework.jpg

3. 扩展

find函数的用法

操作符$in和$slice

timedelta函数

find参数1,找谁,参数2,返回什么数据,用0和1来控制不显示跟显示

不会更改原来的数据结构

条件操作符$in 分片$slice

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值