Python实战计划 如何让数据说话

  1. 提出优秀问题
  2. 通过数据论证,找到答案
  3. 得出结论

笔记

提出正确的问题

正确的提问能解释现象

错误的提问能强行关联无关的事物

正确的提问能验证假设

错误的提问是为了证明自己是对的

正确的提问能探索方向

错误的提问会不知道自己干什么

  • ABTask方法

通过数据论证,找到答案

对比

横向对比,纵向对比

细分

把大的目标分成小的领域

Mindnode划分…

解读数据

样本问题 => 沉默的大多数

因果关联错误

忽略前提 => 有些数据是由前提的

对上一周大作业分析

1
2
3
4
mongoexport -d dataBase -c Info --csv -f title,type,time,price,new,place -o information.csv
2016-08-11T15:27:12.130+0800 csv flag is deprecated; please use --type=csv instead
2016-08-11T15:27:12.143+0800 connected to: localhost
2016-08-11T15:27:12.488+0800 exported 17438 records

file 注意..因为奇怪的原因..每条信息重复了一遍

提出优秀问题

信息齐全度的影响因素

通过数据论证,找到答案

细分问题

横向对比&&纵向对比

本来想用numbers,死机无数次放弃了…好好敲代码

价格

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from pymongo import MongoClient

client = MongoClient('localhost',27017)
db = client['dataBase']
Info = db['Info']
analy = db['analy']
cnts = dict()

op = open('out.txt','w')
for price in analy.find():
if price['price'] in cnts:
cnts[price['price']] = cnts[price['price']]+1
else:
cnts[price['price']] = 1

for item in cnts:
print(item,cnts[item],file=op,sep='\t')

numbers 生成的统计表

然后发现…自己统计错东西了….

重新写一个呗~

除了个1k看数据,似乎不是很明显

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from pymongo import MongoClient

client = MongoClient('localhost',27017)
db = client['dataBase']
Info = db['Info']
analy = db['analy']
cnts = dict()
tot = dict()
op = open('out.txt','w')
for price in analy.find():
ps = int(price['price']) // 100
if ps in cnts:
cnts[ps] = cnts[ps] + 1
tot[ps] = tot[ps] + price['inforNum']
else:
cnts[ps] = 1
tot[ps] = price['inforNum']

for item in sorted(cnts):
if cnts[item] > 1 : #clear special information
print(item ,tot[item]/cnts[item],file=op,sep='\t')
print('from', item * 100, 'to', (item + 1) * 100, 'counts', tot[item] / cnts[item], sep='\t')

由于第一张图可以知道,大部分数据集中在3k以下,所以重新绘制..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from pymongo import MongoClient

client = MongoClient('localhost',27017)
db = client['dataBase']
Info = db['Info']
analy = db['analy']
cnts = dict()
tot = dict()
op = open('out.txt','w')
for price in analy.find():
ps = int(price['price'])
if ps < 3000:#选择精准数据
if ps in cnts:
cnts[ps] = cnts[ps] + 1
tot[ps] = tot[ps] + price['inforNum']
else:
cnts[ps] = 1
tot[ps] = price['inforNum']

for item in sorted(cnts):
if cnts[item] > 1 : #clear special information
print(item ,tot[item]/cnts[item],file=op,sep='\t')
print(item , tot[item] / cnts[item], sep='\t')

看来我是小看了小商品价格填写的认真程度了2333

月份

因为不知道python对于C++pair有什么东西,就自己编写了一个key

但是这样结果似乎意义不大..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from pymongo import MongoClient

client = MongoClient('localhost',27017)
db = client['dataBase']
Info = db['Info']
analy = db['analy']

types = dict()

for month in range(1,13):
cnts = dict()
for data in analy.find():
if data['month'] == None:
pass
m = data['month'] + str('#') + str(data['inforNum'])
if m in cnts:
cnts[m] = cnts[m] + 1
else:
cnts[m] = 1
months = sorted(cnts.keys())
print(months)
for m in months:
print('in month', m, 'info get', cnts[m])
'''
in month #2 info get 3
in month #3 info get 3
in month 01#2 info get 12
in month 01#3 info get 14
in month 02#2 info get 189
in month 02#3 info get 165
in month 02#4 info get 9
in month 03#2 info get 442
in month 03#3 info get 360
in month 03#4 info get 69
in month 04#2 info get 480
in month 04#3 info get 348
in month 04#4 info get 100
in month 05#2 info get 754
in month 05#3 info get 454
in month 05#4 info get 106
in month 06#2 info get 1206
in month 06#3 info get 724
in month 06#4 info get 247
in month 07#2 info get 992
in month 07#3 info get 1059
in month 07#4 info get 270
in month 08#2 info get 249
in month 08#3 info get 325
in month 08#4 info get 105
in month 09#2 info get 1
in month 09#3 info get 3
in month 10#3 info get 1
in month 11#2 info get 2
in month 11#3 info get 4
in month 12#2 info get 11
in month 12#3 info get 11
in month 12#4 info get 1
'''

于是重新求平均值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from pymongo import MongoClient

client = MongoClient('localhost',27017)
db = client['dataBase']
Info = db['Info']
analy = db['analy']

types = dict()

for month in range(1,13):
cnts = dict()
tot = dict()
for data in analy.find():
if data['month'] == None:
continue
m = data['month']
if m in cnts:
cnts[m] = cnts[m] + 1
tot[m] = tot[m] + data['inforNum']
else:
cnts[m] = 1
tot[m] = data['inforNum']
months = sorted(cnts.keys())
#print(months)
for m in months:
print('in month', m, 'tot =',cnts[m],'\t','average info get',tot[m]/ cnts[m])
'''
in month tot = 6 average info get 2.5
in month 01 tot = 26 average info get 2.5384615384615383
in month 02 tot = 363 average info get 2.5041322314049586
in month 03 tot = 871 average info get 2.571756601607348
in month 04 tot = 928 average info get 2.5905172413793105
in month 05 tot = 1314 average info get 2.506849315068493
in month 06 tot = 2177 average info get 2.559485530546624
in month 07 tot = 2321 average info get 2.6889271865575184
in month 08 tot = 679 average info get 2.787923416789396
in month 09 tot = 4 average info get 2.75
in month 10 tot = 1 average info get 3.0
in month 11 tot = 6 average info get 2.6666666666666665
in month 12 tot = 23 average info get 2.5652173913043477
'''

这样就明显多了

分析

  1. 10月份平均值最高是因为数据组数太少
  2. 3~8月数据量多,期中信息平均最多的是7月,或许是因为7月放假了大家比较闲..

类别

类似的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from pymongo import MongoClient

client = MongoClient('localhost',27017)
db = client['dataBase']
Info = db['Info']
analy = db['analy']

types = dict()
tot = dict()
op = open('out.txt','w')

for t in analy.find():
tp = t['type']
if tp in types:
types[tp] = types[tp] + t['inforNum']
tot[tp] = tot[tp] + 1
else:
types[tp] = t['inforNum']
tot[tp] = 1
i = 0
for type in types.keys():
if tot[type] == 1:continue
i = i + 1
st = str(types[type]/tot[type])[0:3]
if i % 5 == 0:
print(type,'ave',st,file = op)
else:
print(type, 'ave', st, file=op,end='\t\t')
if i > 100:
break#only show some data
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
手套 ave 2.3		婴儿浴盆/婴儿浴床 ave 3.0		其他礼品 ave 2.6		陶瓷/景泰蓝 ave 2.2		麦克风 ave 2.5
数码产品 ave 2.2 粮油 ave 2.7 帐篷 ave 3.2 其他电器 ave 2.6 戒指 ave 2.3
奶瓶/奶嘴 ave 3.0 空气净化器 ave 2.6 电脑一体机 ave 2.6 门窗 ave 3.0 血压计/血糖仪 ave 3.0
空调扇 ave 3.0 佛珠 ave 2.1 酸奶机 ave 2.5 电子琴 ave 3.0 家畜/家禽 ave 2.0
蔬菜水果 ave 2.0 农用品/农产品 ave 2.0 冰箱 ave 3.3 电磁炉 ave 2.6 收音机/录音机 ave 3.0
饮水机 ave 2.5 电脑外设 ave 2.0 手链/手串 ave 2.0 架子 ave 2.0 考试/教辅 ave 2.4
灭火器/消防 ave 2.0 Xbox ave 2.5 牛仔裤 ave 2.2 其他锅 ave 2.6 字画 ave 2.0
配饰 ave 2.0 无线网卡 ave 2.0 美甲 ave 3.0 保健美容设备 ave 3.3 冰淇淋机 ave 2.8
无线路由器 ave 2.9 葫芦 ave 2.0 摇摇车 ave 2.7 咖啡 ave 2.5 台球桌 ave 2.9
安全护栏 ave 3.0 项链 ave 2.1 摇椅 ave 4.0 充电器 ave 2.6 燃气灶 ave 2.7
书桌 ave 4.0 设备机械 ave 2.0 其他保健品 ave 2.3 茶几 ave 3.4 美容器材 ave 2.2
饭盒 ave 3.0 其他商用电脑 ave 3.0 苗木 ave 2.2 其他工艺品 ave 2.7 地毯 ave 3.5
大家电 ave 2.0 沙发 ave 3.6 展柜货架 ave 2.0 其他装饰摆设 ave 2.3 前台桌 ave 3.4
其他耳机 ave 2.8 维生素/营养品 ave 2.4 封口机 ave 3.0 烤面包机/面包机 ave 3.0 护肤品 ave 2.0
十字绣 ave 2.2 其他农用品 ave 2.0 电脑椅 ave 3.0 办公桌 ave 3.5 键鼠 ave 2.7
钢琴 ave 2.8 折叠床 ave 3.6 干衣机 ave 3.0 培训课程 ave 2.3 五金工具 ave 2.5
相机/相机配件 ave 2.0 皮鞋/皮靴 ave 2.6 服饰/箱包 ave 2.0 茶叶 ave 2.3 相框 ave 2.5
台式电脑整机 ave 2.7 运动健身 ave 2.0 其他设备/办公用品 ave 2.0 复印传真 ave 2.0 葡萄酒/红酒 ave 3.0
其他桌子 ave 3.5 奶粉 ave 2.9 跑步机 ave 2.1 吸奶器 ave 3.0 空调 ave 3.6
电水壶/热水瓶 ave 2.3 其他家电 ave 2.0 海参 ave 2.5 400电话 ave 2.5 晾衣架 ave 3.6
分裤/短裤 ave 2.0

会有不同啦..但很难分析QAQ

生成数据库Code

想想不如重建一个数据……

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from pymongo import MongoClient

client = MongoClient('localhost',27017)
db = client['dataBase']
Info = db['Info']
analy = db['analy']
i = 0
types = {}

for data in Info.find():
if i % 2 != 0:
infor = 0
if data['new'] != None:
infor = infor + 1
if data['place'] != None:
infor = infor + 1
if data['time'] != None:
infor = infor + 1
if data['title'] != None:
infor = infor + 1
AnalysisInfo = dict(type=data['type'],inforNum=infor,month=data['time'][0:2],price=data['price'])
analy.insert_one(AnalysisInfo)
i = i + 1
1
2
3
4
mongoexport -d dataBase -c analy --csv -f type,month,inforNum,price -o analy.csv
2016-08-11T16:01:44.909+0800 csv flag is deprecated; please use --type=csv instead
2016-08-11T16:01:44.915+0800 connected to: localhost
2016-08-11T16:01:45.004+0800 exported 8719 records

这里本来想直接用numbers搞的结果数据量太大死机play

得出结论

出人意料的是,信息齐全度和月份的关联最大

因为很多人标价1元(假标价)所以坑害了一些数据真实性

类别爬取大类的话想对好分析一些

文章目录
  1. 1. 笔记
    1. 1.1. 提出正确的问题
    2. 1.2. 通过数据论证,找到答案
      1. 1.2.1. 对比
      2. 1.2.2. 细分
    3. 1.3. 解读数据
  2. 2. 对上一周大作业分析
    1. 2.1. 提出优秀问题
    2. 2.2. 通过数据论证,找到答案
    3. 2.3. 细分问题
    4. 2.4. 横向对比&&纵向对比
      1. 2.4.1. 价格
      2. 2.4.2. 月份
        1. 2.4.2.1. 分析
      3. 2.4.3. 类别
    5. 2.5. 生成数据库Code
    6. 2.6. 得出结论