0% found this document useful (0 votes)
13 views5 pages

Pandas Groupby

Uploaded by

ajayakim95
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views5 pages

Pandas Groupby

Uploaded by

ajayakim95
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import pandas as pd

df= pd.read_csv("/content/groups.csv")
df

hlpi_name year own_prop own_wm_prop


prop_hhs \
0 All households 2008 69.7 36.8
100.0
1 Beneficiary 2008 38.3 21.2
11.9
2 Income quintile 1 (low) 2008 61.3 15.5
20.0
3 Income quintile 2 2008 62.8 26.9
20.0
4 Income quintile 3 2008 69.7 45.3
20.0
5 Income quintile 4 2008 73.3 47.3
20.0
6 Income quintile 5 (high) 2008 81.3 49.1
20.0
7 Expenditure quintile 1 (low) 2008 62.1 15.8
20.0
8 Expenditure quintile 2 2008 66.1 27.7
20.0
9 Expenditure quintile 3 2008 62.3 34.7
20.0
10 Expenditure quintile 4 2008 74.2 47.7
20.0
11 Expenditure quintile 5 (high) 2008 83.6 58.2
20.0
12 Maori 2008 47.4 30.5
16.2
13 Superannuitant 2008 87.6 5.1
19.2
14 All households 2011 65.2 32.6
100.0
15 Beneficiary 2011 28.7 13.8
12.3
16 Income quintile 1 (low) 2011 51.7 15.5
20.0
17 Income quintile 2 2011 58.2 24.1
20.0
18 Income quintile 3 2011 63.8 37.3
20.0
19 Income quintile 4 2011 70.6 41.5
20.0
20 Income quintile 5 (high) 2011 81.9 44.6
20.0
21 Expenditure quintile 1 (low) 2011 53.9 11.2
20.0
22 Expenditure quintile 2 2011 55.7 23.9
20.0
23 Expenditure quintile 3 2011 65.9 33.8
20.0
24 Expenditure quintile 4 2011 70.1 41.9
20.0
25 Expenditure quintile 5 (high) 2011 80.6 52.2
20.0
26 Maori 2011 41.3 27.9
17.4
27 Superannuitant 2011 83.9 7.3
20.0
28 All households 2014 66.5 33.7
100.0
29 Beneficiary 2014 24.6 14.5
11.4
30 Income quintile 1 (low) 2014 52.1 16.0
20.0
31 Income quintile 2 2014 58.2 25.7
20.0
32 Income quintile 3 2014 67.1 36.2
20.0
33 Income quintile 4 2014 72.5 44.4
20.0
34 Income quintile 5 (high) 2014 82.8 46.1
20.0
35 Expenditure quintile 1 (low) 2014 54.9 12.7
20.0
36 Expenditure quintile 2 2014 58.4 24.3
20.0
37 Expenditure quintile 3 2014 66.5 34.4
20.1
38 Expenditure quintile 4 2014 70.0 42.1
20.0
39 Expenditure quintile 5 (high) 2014 82.9 55.0
20.0
40 Maori 2014 44.6 29.6
17.5
41 Superannuitant 2014 88.1 11.6
21.8
42 All households 2017 66.6 33.0
100.0
43 Beneficiary 2017 22.8 10.8
7.8
44 Income quintile 1 (low) 2017 54.1 12.9
20.0
45 Income quintile 2 2017 55.9 23.6
20.0
46 Income quintile 3 2017 64.1 37.5
20.0
47 Income quintile 4 2017 73.9 43.6
20.0
48 Income quintile 5 (high) 2017 84.9 47.6
20.0
49 Expenditure quintile 1 (low) 2017 53.8 9.7
20.0
50 Expenditure quintile 2 2017 57.6 23.7
20.0
51 Expenditure quintile 3 2017 64.3 34.7
20.0
52 Expenditure quintile 4 2017 73.8 45.7
20.0
53 Expenditure quintile 5 (high) 2017 83.3 51.2
20.0
54 Maori 2017 49.8 30.2
17.5
55 Superannuitant 2017 84.4 8.5
23.1

age size income expenditure eqv_income eqv_exp


0 35.9 2.7 46704 42394 26869 25132
1 29.9 2.6 23404 25270 14258 15824
2 40.0 2.3 16747 21145 13402 14408
3 34.7 2.8 31308 29855 18917 18266
4 31.5 3.0 49106 46561 26870 24672
5 35.3 2.6 61674 52776 36691 31958
6 39.3 2.5 96861 72822 55637 42932
7 38.7 2.5 23680 16413 15190 11015
8 36.1 2.7 34155 29085 20357 18121
9 33.0 2.8 49771 42662 27203 25132
10 35.1 2.7 60863 59015 34547 34167
11 36.7 2.5 77434 89053 46269 51550
12 28.9 3.2 42885 35312 23096 19797
13 70.3 1.6 22367 21538 17203 17211
14 36.3 2.6 53103 46098 30833 27335
15 28.0 2.7 25902 27605 16097 16685
16 36.3 2.4 19787 24224 15414 16221
17 35.0 2.9 37370 34200 21998 20586
18 33.4 2.9 54894 49431 30833 28130
19 36.8 2.6 69183 55569 42084 33019
20 40.9 2.4 106227 71815 63106 44712
21 37.3 2.6 27501 18877 17612 13077
22 35.1 2.7 38932 32790 22895 20168
23 35.3 2.8 56117 46651 32053 27335
24 35.3 2.7 64643 60862 38625 36203
25 39.0 2.4 86431 90268 52895 52769
26 28.3 3.2 51486 42801 27219 22651
27 69.7 1.6 28064 25436 21335 20147
28 37.0 2.6 57359 49330 33426 29683
29 27.3 2.5 26569 27348 17706 17893
30 37.4 2.4 22822 25809 17168 17555
31 34.2 2.9 41107 38498 24162 22743
32 34.8 2.8 58007 52941 33426 30133
33 38.2 2.6 78889 65874 47882 38147
34 41.0 2.4 122881 80806 72233 49571
35 38.5 2.6 30138 19997 19171 13678
36 35.7 2.7 42898 35822 25743 21961
37 36.4 2.8 60890 49330 33139 29706
38 36.5 2.6 80597 66519 45599 39787
39 37.9 2.5 97676 97823 60056 56910
40 30.2 3.1 56765 43582 28428 24850
41 68.8 1.7 33168 29328 25404 23456
42 37.4 2.7 64066 54293 36146 31409
43 29.1 2.8 29947 30054 16822 17655
44 40.3 2.3 22733 26775 18859 17850
45 35.2 3.0 45704 43676 25815 24077
46 34.7 3.1 66652 58065 36146 30908
47 37.1 2.7 85856 68119 50425 40219
48 41.1 2.5 133270 90983 79607 54244
49 40.0 2.6 33596 20167 20674 14437
50 36.1 2.8 50561 38052 27694 22792
51 35.7 2.9 65099 54936 35959 31409
52 37.1 2.6 81699 72718 47432 42940
53 38.3 2.6 109930 115746 67081 67680
54 32.0 3.1 62193 50982 31571 26395
55 69.9 1.6 33911 30486 24803 23968

groups=df.groupby('hlpi_name')
df['hlpi_name'].drop_duplicates()

0 All households
1 Beneficiary
2 Income quintile 1 (low)
3 Income quintile 2
4 Income quintile 3
5 Income quintile 4
6 Income quintile 5 (high)
7 Expenditure quintile 1 (low)
8 Expenditure quintile 2
9 Expenditure quintile 3
10 Expenditure quintile 4
11 Expenditure quintile 5 (high)
12 Maori
13 Superannuitant
Name: hlpi_name, dtype: object

groups.get_group('Income quintile 1 (low)')


hlpi_name year own_prop own_wm_prop prop_hhs
age \
2 Income quintile 1 (low) 2008 61.3 15.5 20.0
40.0
16 Income quintile 1 (low) 2011 51.7 15.5 20.0
36.3
30 Income quintile 1 (low) 2014 52.1 16.0 20.0
37.4
44 Income quintile 1 (low) 2017 54.1 12.9 20.0
40.3

size income expenditure eqv_income eqv_exp


2 2.3 16747 21145 13402 14408
16 2.4 19787 24224 15414 16221
30 2.4 22822 25809 17168 17555
44 2.3 22733 26775 18859 17850

You might also like