coursera-数据管理与可视化-week 2 作业

import pandas
import numpy

data = pandas.read_csv('nesarc_pds.csv', low_memory=False)
print(len(data))
print(len(data.columns))

data['S2BQ1A2']=data['S2BQ1A2'].convert_objects(convert_numeric=True)
data['S2AQ5B']=data['S2AQ5B'].convert_objects(convert_numeric=True)
data['S2AQ5CR']=data['S2AQ5CR'].convert_objects(convert_numeric=True)
data['S2AQ5D']=data['S2AQ5D'].convert_objects(convert_numeric=True)
print('counts for S2BQ1A2_alcohol dependence ever want to drink more')
ct1=data.groupby('S2BQ1A2').size()
print(ct1)
print('percentages for S2BQ1A2_alcohol dependence ever want to drink more')
pt1=data.groupby('S2BQ1A2').size()*100/len(data)
print(pt1)

print('counts for S2AQ5B_how often drank beer in last 12 months')
ct2=data.groupby('S2AQ5B').size()
print(ct2)
print('percentages for S2AQ5B_how often drank beer in last 12 months')
pt2=data.groupby('S2AQ5B').size()*100/len(data)
print(pt2)

print('counts for S2AQ5CR_size of typical bottle, can and glass')
ct3=data.groupby('S2AQ5CR').size()
print(ct3)
print('percentages for S2AQ5CR_size of typical bottle, can and glass')
pt3=data.groupby('S2AQ5CR').size()*100/len(data)
print(pt3)

print('counts for S2AQ5D_number of beer consumed on days in last 12 months')
ct4=data.groupby('S2AQ5D').size()
print(ct4)
print('percentages for S2AQ5D_number of beer consumed on days in last 12 months')
pt4=data.groupby('S2AQ5D').size()*100/len(data)
print(pt4)

console:

counts for S2BQ1A2_alcohol dependence ever want to drink more
S2BQ1A2
1.0     4499
2.0    29949
9.0      379
dtype: int64
percentages for S2BQ1A2_alcohol dependence ever want to drink more
S2BQ1A2
1.0    10.440211
2.0    69.498526
9.0     0.879493
dtype: float64
counts for S2AQ5B_how often drank beer in last 12 months
S2AQ5B
1.0      836
2.0      645
3.0     1535
4.0     2190
5.0     2451
6.0     2603
7.0     2127
8.0     1194
9.0     2268
10.0    2442
99.0      55
dtype: int64
percentages for S2AQ5B_how often drank beer in last 12 months
S2AQ5B
1.0     1.939990
2.0     1.496763
3.0     3.562063
4.0     5.082032
5.0     5.687699
6.0     6.040424
7.0     4.935836
8.0     2.770752
9.0     5.263036
10.0    5.666814
99.0    0.127631
dtype: float64
counts for S2AQ5CR_size of typical bottle, can and glass
S2AQ5CR
1.0         7
3.0         5
4.0         6
5.0        13
6.0         4
7.0        13
9.0      1429
10.0        2
11.0      642
12.0    15026
14.0      606
17.0      207
18.0       14
19.0      145
20.0        1
21.0        1
29.0        1
30.0        1
36.0       89
41.0       73
42.0        6
47.0        4
99.0       51
dtype: int64
percentages for S2AQ5CR_size of typical bottle, can and glass
S2AQ5CR
1.0      0.016244
3.0      0.011603
4.0      0.013923
5.0      0.030167
6.0      0.009282
7.0      0.030167
9.0      3.316084
10.0     0.004641
11.0     1.489801
12.0    34.868772
14.0     1.406261
17.0     0.480356
18.0     0.032488
19.0     0.336482
20.0     0.002321
21.0     0.002321
29.0     0.002321
30.0     0.002321
36.0     0.206530
41.0     0.169401
42.0     0.013923
47.0     0.009282
99.0     0.118349
dtype: float64
counts for S2AQ5D_number of beer consumed on days in last 12 months
S2AQ5D
1.0     7122
2.0     4938
3.0     2564
4.0     1224
5.0      507
6.0     1128
7.0      118
8.0      205
9.0       28
10.0     108
11.0       6
12.0     231
13.0       3
14.0       6
15.0      21
16.0       1
17.0       4
18.0      18
20.0       7
24.0      23
25.0       1
30.0       3
36.0       1
42.0       1
99.0      78
dtype: int64
percentages for S2AQ5D_number of beer consumed on days in last 12 months
S2AQ5D
1.0     16.527046
2.0     11.458938
3.0      5.949922
4.0      2.840369
5.0      1.176525
6.0      2.617595
7.0      0.273826
8.0      0.475715
9.0      0.064976
10.0     0.250621
11.0     0.013923
12.0     0.536050
13.0     0.006962
14.0     0.013923
15.0     0.048732
16.0     0.002321
17.0     0.009282
18.0     0.041770
20.0     0.016244
24.0     0.053373
25.0     0.002321
30.0     0.006962
36.0     0.002321
42.0     0.002321
99.0     0.181004
dtype: float64

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值