【statistics】查看2018.4.25日理想论坛某ID在一天中的活跃情况

用于统计的sum.py代码:

import re
import pymysql

# 入口函数
def main():
    dic={'00':0,'01':0,'02':0,'03':0,'04':0,'05':0,'06':0,'07':0,'08':0,'09':0,'10':0,'11':0,'12':0,'13':0,'14':0,'15':0,'16':0,'17':0,'18':0,'19':0,'20':0,'21':0,'22':0,'23':0}

    conn=pymysql.connect(host='127.0.0.1',user='root',passwd='12345678',db='test',charset='utf8')

    cs=conn.cursor()
    cs.execute("select * from topic0426 where author='天山剑阁' and tdate='2018-4-25'")
    results = cs.fetchall()

    for row in results:
        ttime=row[4]
        hour=ttime.split(':')[0]
        dic[hour]=dic[hour]+1

    conn.close()

    print(dic)
# 开始
main()

统计后的数据为:

{'00': 0, '01': 0, '02': 0, '03': 0, '04': 0, '05': 0, '06': 0, '07': 0, '08': 1, '09': 34, '10': 39, '11': 30, '12': 32, '13': 0, '14': 22, '15': 38, '16': 0, '17': 0, '18': 0, '19': 0, '20': 0, '21': 58, '22': 46, '23': 0}

展现出来则是:

另附上几个ID的统计图,通过这些活跃时间图可以观察出他们一个方面的用户行为:

 

转载于:https://www.cnblogs.com/xiandedanteng/p/8962201.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值