In [3]:
#!pip install pandasreporter
import pandasreporter as pr
Collecting pandasreporter
Downloading pandasreporter-0.0.1.tar.gz
Collecting pandas (from pandasreporter)
Using cached pandas-0.19.2-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Requirement already satisfied: requests in /Volumes/Storage/proj/virt-proj/data-projects/lib/python3.6/site-packages (from pandasreporter)
Requirement already satisfied: geoid in /Volumes/Storage/proj/virt-proj/data-projects/lib/python3.6/site-packages (from pandasreporter)
Requirement already satisfied: python-dateutil>=2 in /Volumes/Storage/proj/virt-proj/data-projects/lib/python3.6/site-packages (from pandas->pandasreporter)
Requirement already satisfied: pytz>=2011k in /Volumes/Storage/proj/virt-proj/data-projects/lib/python3.6/site-packages (from pandas->pandasreporter)
Collecting numpy>=1.7.0 (from pandas->pandasreporter)
Downloading numpy-1.12.1-cp36-cp36m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (4.4MB)
100% |████████████████████████████████| 4.4MB 268kB/s ta 0:00:01
Requirement already satisfied: six in /Volumes/Storage/proj/virt-proj/data-projects/lib/python3.6/site-packages (from geoid->pandasreporter)
Installing collected packages: numpy, pandas, pandasreporter
Running setup.py install for pandasreporter ... done
Successfully installed numpy-1.12.1 pandas-0.19.2 pandasreporter-0.0.1
In [4]:
df = pr.get_dataframe('B01001', '140', '05000US06073')
df.head()
Out[4]:
geoid
name
B01001001
B01001001_m90
B01001002
B01001002_m90
B01001003
B01001003_m90
B01001004
B01001004_m90
...
B01001045
B01001045_m90
B01001046
B01001046_m90
B01001047
B01001047_m90
B01001048
B01001048_m90
B01001049
B01001049_m90
0
14000US06073000100
Census Tract 1, San Diego, CA
2716.0
206.0
1251.0
162.0
53.0
39.0
64.0
43.0
...
81.0
43.0
60.0
37.0
27.0
25.0
126.0
57.0
115.0
71.0
1
14000US06073000201
Census Tract 2.01, San Diego, CA
2223.0
260.0
921.0
121.0
54.0
53.0
56.0
31.0
...
96.0
57.0
64.0
43.0
53.0
37.0
58.0
46.0
61.0
51.0
2
14000US06073000202
Census Tract 2.02, San Diego, CA
4683.0
398.0
2323.0
253.0
115.0
84.0
54.0
42.0
...
45.0
63.0
48.0
39.0
78.0
65.0
25.0
28.0
31.0
38.0
3
14000US06073000300
Census Tract 3, San Diego, CA
4875.0
417.0
2642.0
320.0
51.0
59.0
0.0
12.0
...
80.0
54.0
144.0
66.0
7.0
16.0
24.0
31.0
128.0
112.0
4
14000US06073000400
Census Tract 4, San Diego, CA
3606.0
272.0
2290.0
267.0
115.0
76.0
31.0
46.0
...
3.0
6.0
113.0
91.0
3.0
7.0
49.0
50.0
12.0
12.0
5 rows × 100 columns
In [5]:
list(df.ct_columns.sort_values('name').columns)
Out[5]:
['geoid',
'name',
'B01001001 Total',
'Margins for B01001001 Total',
'B01001002 Total Male',
'Margins for B01001002 Total Male',
'B01001003 Total Male Under 5 years',
'Margins for B01001003 Total Male Under 5 years',
'B01001004 Total Male 5 to 9 years',
'Margins for B01001004 Total Male 5 to 9 years',
'B01001005 Total Male 10 to 14 years',
'Margins for B01001005 Total Male 10 to 14 years',
'B01001006 Total Male 15 to 17 years',
'Margins for B01001006 Total Male 15 to 17 years',
'B01001007 Total Male 18 and 19 years',
'Margins for B01001007 Total Male 18 and 19 years',
'B01001008 Total Male 20 years',
'Margins for B01001008 Total Male 20 years',
'B01001009 Total Male 21 years',
'Margins for B01001009 Total Male 21 years',
'B01001010 Total Male 22 to 24 years',
'Margins for B01001010 Total Male 22 to 24 years',
'B01001011 Total Male 25 to 29 years',
'Margins for B01001011 Total Male 25 to 29 years',
'B01001012 Total Male 30 to 34 years',
'Margins for B01001012 Total Male 30 to 34 years',
'B01001013 Total Male 35 to 39 years',
'Margins for B01001013 Total Male 35 to 39 years',
'B01001014 Total Male 40 to 44 years',
'Margins for B01001014 Total Male 40 to 44 years',
'B01001015 Total Male 45 to 49 years',
'Margins for B01001015 Total Male 45 to 49 years',
'B01001016 Total Male 50 to 54 years',
'Margins for B01001016 Total Male 50 to 54 years',
'B01001017 Total Male 55 to 59 years',
'Margins for B01001017 Total Male 55 to 59 years',
'B01001018 Total Male 60 and 61 years',
'Margins for B01001018 Total Male 60 and 61 years',
'B01001019 Total Male 62 to 64 years',
'Margins for B01001019 Total Male 62 to 64 years',
'B01001020 Total Male 65 and 66 years',
'Margins for B01001020 Total Male 65 and 66 years',
'B01001021 Total Male 67 to 69 years',
'Margins for B01001021 Total Male 67 to 69 years',
'B01001022 Total Male 70 to 74 years',
'Margins for B01001022 Total Male 70 to 74 years',
'B01001023 Total Male 75 to 79 years',
'Margins for B01001023 Total Male 75 to 79 years',
'B01001024 Total Male 80 to 84 years',
'Margins for B01001024 Total Male 80 to 84 years',
'B01001025 Total Male 85 years and over',
'Margins for B01001025 Total Male 85 years and over',
'B01001026 Total Female',
'Margins for B01001026 Total Female',
'B01001027 Total Female Under 5 years',
'Margins for B01001027 Total Female Under 5 years',
'B01001028 Total Female 5 to 9 years',
'Margins for B01001028 Total Female 5 to 9 years',
'B01001029 Total Female 10 to 14 years',
'Margins for B01001029 Total Female 10 to 14 years',
'B01001030 Total Female 15 to 17 years',
'Margins for B01001030 Total Female 15 to 17 years',
'B01001031 Total Female 18 and 19 years',
'Margins for B01001031 Total Female 18 and 19 years',
'B01001032 Total Female 20 years',
'Margins for B01001032 Total Female 20 years',
'B01001033 Total Female 21 years',
'Margins for B01001033 Total Female 21 years',
'B01001034 Total Female 22 to 24 years',
'Margins for B01001034 Total Female 22 to 24 years',
'B01001035 Total Female 25 to 29 years',
'Margins for B01001035 Total Female 25 to 29 years',
'B01001036 Total Female 30 to 34 years',
'Margins for B01001036 Total Female 30 to 34 years',
'B01001037 Total Female 35 to 39 years',
'Margins for B01001037 Total Female 35 to 39 years',
'B01001038 Total Female 40 to 44 years',
'Margins for B01001038 Total Female 40 to 44 years',
'B01001039 Total Female 45 to 49 years',
'Margins for B01001039 Total Female 45 to 49 years',
'B01001040 Total Female 50 to 54 years',
'Margins for B01001040 Total Female 50 to 54 years',
'B01001041 Total Female 55 to 59 years',
'Margins for B01001041 Total Female 55 to 59 years',
'B01001042 Total Female 60 and 61 years',
'Margins for B01001042 Total Female 60 and 61 years',
'B01001043 Total Female 62 to 64 years',
'Margins for B01001043 Total Female 62 to 64 years',
'B01001044 Total Female 65 and 66 years',
'Margins for B01001044 Total Female 65 and 66 years',
'B01001045 Total Female 67 to 69 years',
'Margins for B01001045 Total Female 67 to 69 years',
'B01001046 Total Female 70 to 74 years',
'Margins for B01001046 Total Female 70 to 74 years',
'B01001047 Total Female 75 to 79 years',
'Margins for B01001047 Total Female 75 to 79 years',
'B01001048 Total Female 80 to 84 years',
'Margins for B01001048 Total Female 80 to 84 years',
'B01001049 Total Female 85 years and over',
'Margins for B01001049 Total Female 85 years and over']
In [4]:
c1 = df.lookup('040')
c2 = df.lookup('044')
cols = df.ix[:,c1.col_position. c2.col_position+1]
cols
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-4-874ad0adc160> in <module>()
1 c1 = df.lookup('040')
2 c2 = df.lookup('044')
----> 3 cols = df.ix[:,c1.col_position. c2.col_position+1]
4 cols
AttributeError: 'int' object has no attribute 'c2'
In [ ]:
Content source: sandiegodata/age-friendly-communities
Similar notebooks: