In [1]:
import seaborn as sns
import metapack as mp
import pandas as pd
import numpy as np
import rowgenerators as rg
import matplotlib.pyplot as plt
from IPython.display import display 

%matplotlib inline
sns.set_context('notebook')
mp.jupyter.init()

In [21]:
pkg = mp.jupyter.open_package()
#pkg = mp.jupyter.open_source_package()
pkg


Out[21]:

LA County Homeless Survey

economicrt.org-homeless_survey-2011e2017-4 Last Update: 2019-01-25T04:15:29

Data from Demographic Surveys and HMIS Records 2011 to 2017

This dataset consists of records of in-person surveys of homeless individuals in Los Angeles county, from 2011 to 2017, inclusive. The original data is collected from annual surveys that are part of the annual Point In Time Count of homeless individuqals conducted by the Los Angeles Homeless Services Authority. The data is published by The Economic Roundtable.

The data in this package is significantly altered from the source file to make analysis easier. Changes include:

  • Added 'raceeth' field, which recodes the very many race/ethnicity values to a much simpler set that hamonizes with US Census categories.
  • Added 'sex' field, which recodes the 'gender' field.
  • Broke out the type+year combination in 'survey_year' into two values.

The Race/Ethnicity categories are:

  • hisp: Hispanic or Latino, of any race
  • nhwhite: Non hispanic white
  • black: Non hispanic Black or African American
  • aian: Non hispanic American Indian / Alaskan Native
  • asian: Non hispanic Asian
  • nhopi: Non hispanic Native Hawaiian / Other Pacific Islander
  • other: Other race or multiple races

Versions

  1. Initial Version
  2. Added schema descriptions
  3. Broke out the survey_year into two fields, survey_type and year
  4. Improved Metadata

Documentation Links

Contacts

Resources

  • homeless_survey. Homeless survey data, with recoded race, ethnicity, and sex

References


In [22]:
df = pkg.resource('homeless_survey').dataframe()

In [4]:
t1 = pd.pivot_table(df[df.sex!='U'], index='raceeth',columns='sex', values='mental_illness', 
                   margins=True, aggfunc='count')

t1.loc[:,'All']


Out[4]:
raceeth
aian         804
asian        749
black      31692
hisp       19543
nhopi        355
nhwhite    15009
other       3745
All        71897
Name: All, dtype: int64

In [5]:
t2 = pd.pivot_table(df[df.sex!='U'], index='raceeth',columns='sex', values='mental_illness', 
                   margins=True, aggfunc='sum')
t2


Out[5]:
sex F M All
raceeth
aian 109 163 272
asian 91 114 205
black 3125 5634 8759
hisp 1501 2369 3870
nhopi 39 57 96
nhwhite 1625 3140 4765
other 391 660 1051
All 6881 12137 19018

In [6]:
t2/t1


Out[6]:
sex F M All
raceeth
aian 0.386525 0.312261 0.338308
asian 0.366935 0.227545 0.273698
black 0.301845 0.264024 0.276379
hisp 0.241902 0.177613 0.198025
nhopi 0.330508 0.240506 0.270423
nhwhite 0.368899 0.296115 0.317476
other 0.334474 0.256211 0.280641
All 0.302063 0.247104 0.264517

In [7]:
pd.pivot_table(df[df.sex!='U'], index='raceeth',columns='sex', values='mental_illness', 
                   margins=True, aggfunc='mean')


Out[7]:
sex F M All
raceeth
aian 0.386525 0.312261 0.338308
asian 0.366935 0.227545 0.273698
black 0.301845 0.264024 0.276379
hisp 0.241902 0.177613 0.198025
nhopi 0.330508 0.240506 0.270423
nhwhite 0.368899 0.296115 0.317476
other 0.334474 0.256211 0.280641
All 0.302063 0.247104 0.264517

In [8]:
tracts = rg.geoframe('census://CA/140')
tracts.plot()


Out[8]:
<matplotlib.axes._subplots.AxesSubplot at 0x10b9794a8>

In [9]:
tj = tracts.merge(df, on='geoid')
tj.head()


Out[9]:
statefp countyfp tractce geoid name namelsad mtfcc funcstat aland awater ... physical_disability mental_illness alcohol_abuse drug_abuse drug_alcohol_history hiv_positive part_time full_time unemployed_looking unemployed_not_looking
0 06 037 204920 14000US06037204920 2049.20 Census Tract 2049.20 G5020 S 909972 0 ... 0 1 0.0 0.0 1 0 0.0 0.0 0.0 0.0
1 06 037 204920 14000US06037204920 2049.20 Census Tract 2049.20 G5020 S 909972 0 ... 0 0 0.0 0.0 1 0 0.0 0.0 0.0 0.0
2 06 037 205120 14000US06037205120 2051.20 Census Tract 2051.20 G5020 S 1466129 0 ... 0 0 0.0 0.0 1 0 0.0 0.0 1.0 0.0
3 06 037 205120 14000US06037205120 2051.20 Census Tract 2051.20 G5020 S 1466129 0 ... 0 1 0.0 0.0 0 0 0.0 0.0 0.0 1.0
4 06 037 205120 14000US06037205120 2051.20 Census Tract 2051.20 G5020 S 1466129 0 ... 1 1 0.0 1.0 1 0 0.0 0.0 0.0 1.0

5 rows × 45 columns


In [10]:
len(tj)


Out[10]:
40513

In [11]:
df['n'] = 1
t = df.groupby('geoid').sum()
t['mi_rate'] = t.mental_illness / t['n']
t2 = tracts.set_index('geoid').join(t[['mi_rate', 'n']], how='right')
t2['z'] = np.log(t2['n']/t2['n'].std())
t2.plot(column='z', figsize=(12,12))


Out[11]:
<matplotlib.axes._subplots.AxesSubplot at 0x12d1b1898>

In [12]:
t2.z.describe()


Out[12]:
count    942.000000
mean      -3.124980
std        1.539776
min       -5.338555
25%       -4.239943
50%       -3.259114
75%       -2.119680
max        3.022685
Name: z, dtype: float64

In [13]:
t2.to_csv('lacount.csv')

In [18]:
t2


Out[18]:
statefp countyfp tractce name namelsad mtfcc funcstat aland awater intptlat intptlon geometry mi_rate n z
geoid
14000US06037101110 06 037 101110 1011.10 Census Tract 1011.10 G5020 S 1142402.0 0.0 +34.2594737 -118.2929869 POLYGON ((-118.302291 34.258697, -118.300912 3... 0.500000 2 -4.645408
14000US06037101210 06 037 101210 1012.10 Census Tract 1012.10 G5020 S 650690.0 0.0 +34.2529724 -118.2907309 POLYGON ((-118.299451 34.255978, -118.297919 3... 0.666667 12 -2.853649
14000US06037101220 06 037 101220 1012.20 Census Tract 1012.20 G5020 S 698886.0 0.0 +34.2516083 -118.2816328 POLYGON ((-118.285925 34.252274, -118.285924 3... 0.500000 18 -2.448184
14000US06037101300 06 037 101300 1013 Census Tract 1013 G5020 S 2581214.0 0.0 +34.2487734 -118.2709978 POLYGON ((-118.278224 34.250679, -118.278224 3... 0.222222 36 -1.755036
14000US06037101400 06 037 101400 1014 Census Tract 1014 G5020 S 6310056.0 0.0 +34.2428521 -118.2941612 POLYGON ((-118.322382 34.249631, -118.322116 3... 0.125000 16 -2.565967
14000US06037102103 06 037 102103 1021.03 Census Tract 1021.03 G5020 S 1186484.0 0.0 +34.2250792 -118.3541880 POLYGON ((-118.365326 34.228703, -118.363961 3... 0.466667 15 -2.630505
14000US06037102105 06 037 102105 1021.05 Census Tract 1021.05 G5020 S 492761.0 0.0 +34.2098760 -118.3492653 POLYGON ((-118.35307 34.20878, -118.353066 34.... 0.166667 6 -3.546796
14000US06037102107 06 037 102107 1021.07 Census Tract 1021.07 G5020 S 12908567.0 13753.0 +34.2409052 -118.3396019 POLYGON ((-118.367885 34.239393, -118.367879 3... 0.125000 8 -3.259114
14000US06037103100 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 0.000000 1 -5.338555
14000US06037103101 06 037 103101 1031.01 Census Tract 1031.01 G5020 S 2029809.0 0.0 +34.2732407 -118.3078874 POLYGON ((-118.317596 34.273869, -118.317575 3... 0.200000 5 -3.729118
14000US06037103200 06 037 103200 1032 Census Tract 1032 G5020 S 7414589.0 0.0 +34.2733525 -118.3402264 POLYGON ((-118.373034 34.274252, -118.373023 3... 0.290909 55 -1.331222
14000US06037103300 06 037 103300 1033 Census Tract 1033 G5020 S 6141955.0 0.0 +34.2573786 -118.3554785 POLYGON ((-118.375225 34.256954, -118.374098 3... 0.250000 8 -3.259114
14000US06037103400 06 037 103400 1034 Census Tract 1034 G5020 S 2500752.0 0.0 +34.2548355 -118.3139736 POLYGON ((-118.329998 34.259677, -118.32964 34... 0.166667 18 -2.448184
14000US06037104105 06 037 104105 1041.05 Census Tract 1041.05 G5020 S 584710.0 0.0 +34.2761480 -118.4046862 POLYGON ((-118.411686 34.273686, -118.408402 3... 0.400000 10 -3.035970
14000US06037104124 06 037 104124 1041.24 Census Tract 1041.24 G5020 S 4479383.0 980.0 +34.2900933 -118.3741930 POLYGON ((-118.391805 34.277624, -118.391596 3... 0.000000 1 -5.338555
14000US06037104204 06 037 104204 1042.04 Census Tract 1042.04 G5020 S 2664512.0 3735.0 +34.2912875 -118.3931176 POLYGON ((-118.411424 34.28443, -118.408542 34... 0.250000 12 -2.853649
14000US06037104320 06 037 104320 1043.20 Census Tract 1043.20 G5020 S 1212169.0 0.0 +34.2731324 -118.4202492 POLYGON ((-118.428761 34.272363, -118.428538 3... 0.306452 310 0.398017
14000US06037104401 06 037 104401 1044.01 Census Tract 1044.01 G5020 S 681117.0 0.0 +34.2670388 -118.4327217 POLYGON ((-118.440877 34.267053, -118.44016 34... 0.000000 2 -4.645408
14000US06037104403 06 037 104403 1044.03 Census Tract 1044.03 G5020 S 693083.0 0.0 +34.2587946 -118.4344932 POLYGON ((-118.443266 34.266618, -118.443142 3... 0.181818 11 -2.940660
14000US06037104500 06 037 104500 1045 Census Tract 1045 G5020 S 531002.0 0.0 +34.2555108 -118.4257479 POLYGON ((-118.432118 34.258781, -118.431297 3... 0.000000 31 -1.904568
14000US06037104610 06 037 104610 1046.10 Census Tract 1046.10 G5020 S 592138.0 0.0 +34.2604355 -118.4189927 POLYGON ((-118.424608 34.264261, -118.423825 3... 0.315789 19 -2.394116
14000US06037104620 06 037 104620 1046.20 Census Tract 1046.20 G5020 S 531171.0 0.0 +34.2579043 -118.4224647 POLYGON ((-118.428013 34.261776, -118.427192 3... 0.000000 3 -4.239943
14000US06037104702 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 0.250000 4 -3.952261
14000US06037104704 06 037 104704 1047.04 Census Tract 1047.04 G5020 S 1662660.0 0.0 +34.2625316 -118.4088637 POLYGON ((-118.418176 34.263673, -118.417139 3... 0.615385 13 -2.773606
14000US06037104821 06 037 104821 1048.21 Census Tract 1048.21 G5020 S 531802.0 0.0 +34.2465705 -118.4162955 POLYGON ((-118.422664 34.249843, -118.421021 3... 0.000000 7 -3.392645
14000US06037104822 06 037 104822 1048.22 Census Tract 1048.22 G5020 S 604352.0 0.0 +34.2458703 -118.4209447 POLYGON ((-118.428603 34.25078999999999, -118.... 0.000000 2 -4.645408
14000US06037106020 06 037 106020 1060.20 Census Tract 1060.20 G5020 S 2010765.0 7144.0 +34.3232264 -118.4294854 POLYGON ((-118.439827 34.316396, -118.439745 3... 0.076923 39 -1.674994
14000US06037106112 06 037 106112 1061.12 Census Tract 1061.12 G5020 S 3222752.0 0.0 +34.3054910 -118.4124422 POLYGON ((-118.427822 34.315448, -118.426332 3... 0.055556 18 -2.448184
14000US06037106113 06 037 106113 1061.13 Census Tract 1061.13 G5020 S 1443466.0 0.0 +34.3061546 -118.4222071 POLYGON ((-118.432668 34.311129, -118.432436 3... 0.357143 14 -2.699498
14000US06037106404 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 0.500000 2 -4.645408
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
14000US06037910713 06 037 910713 9107.13 Census Tract 9107.13 G5020 S 1994639.0 1602.0 +34.5770039 -118.0366123 POLYGON ((-118.048183 34.580146, -118.045085 3... 0.500000 4 -3.952261
14000US06037910714 06 037 910714 9107.14 Census Tract 9107.14 G5020 S 1003314.0 651.0 +34.5616733 -118.0375369 POLYGON ((-118.045198 34.558463, -118.045183 3... 0.500000 6 -3.546796
14000US06037910807 06 037 910807 9108.07 Census Tract 9108.07 G5020 S 5510454.0 0.0 +34.4410273 -118.4105719 POLYGON ((-118.423691 34.427014, -118.423687 3... 0.000000 2 -4.645408
14000US06037910810 06 037 910810 9108.10 Census Tract 9108.10 G5020 S 23831092.0 7265.0 +34.4595477 -118.3532786 POLYGON ((-118.393355 34.437068, -118.393354 3... 0.000000 3 -4.239943
14000US06037910811 06 037 910811 9108.11 Census Tract 9108.11 G5020 S 323303308.0 564531.0 +34.4085483 -118.1235922 POLYGON ((-118.405289 34.380956, -118.397239 3... 0.250000 8 -3.259114
14000US06037920015 06 037 920015 9200.15 Census Tract 9200.15 G5020 S 5860174.0 1128.0 +34.4731193 -118.5275931 POLYGON ((-118.547492 34.468124, -118.547484 3... 0.500000 2 -4.645408
14000US06037920020 06 037 920020 9200.20 Census Tract 9200.20 G5020 S 10835819.0 18673.0 +34.4715219 -118.4990703 POLYGON ((-118.510127 34.454165, -118.508498 3... 1.000000 1 -5.338555
14000US06037920023 06 037 920023 9200.23 Census Tract 9200.23 G5020 S 1343029.0 0.0 +34.4234641 -118.4919398 POLYGON ((-118.50367 34.425403, -118.502261 34... 0.000000 3 -4.239943
14000US06037920031 06 037 920031 9200.31 Census Tract 9200.31 G5020 S 6360356.0 1241.0 +34.3994653 -118.4836245 POLYGON ((-118.503089 34.410575, -118.50235 34... 0.200000 10 -3.035970
14000US06037920033 06 037 920033 9200.33 Census Tract 9200.33 G5020 S 3439062.0 1532.0 +34.4596282 -118.4326143 POLYGON ((-118.445362 34.451595, -118.441958 3... 0.000000 1 -5.338555
14000US06037920034 06 037 920034 9200.34 Census Tract 9200.34 G5020 S 9013714.0 0.0 +34.4388053 -118.4511824 POLYGON ((-118.477541 34.436412, -118.477529 3... 0.500000 12 -2.853649
14000US06037920040 06 037 920040 9200.40 Census Tract 9200.40 G5020 S 2960456.0 0.0 +34.4356080 -118.4274646 POLYGON ((-118.441437 34.426858, -118.441307 3... 0.000000 2 -4.645408
14000US06037920043 06 037 920043 9200.43 Census Tract 9200.43 G5020 S 18679074.0 11223.0 +34.3909956 -118.4411518 POLYGON ((-118.493386 34.377629, -118.493113 3... 0.307692 13 -2.773606
14000US06037920104 06 037 920104 9201.04 Census Tract 9201.04 G5020 S 158260183.0 34125.0 +34.5728918 -118.7433220 POLYGON ((-118.820915 34.665851, -118.820736 3... 0.000000 1 -5.338555
14000US06037920107 06 037 920107 9201.07 Census Tract 9201.07 G5020 S 11399076.0 13278.0 +34.4525395 -118.5775170 POLYGON ((-118.613464 34.449559, -118.613421 3... 0.333333 3 -4.239943
14000US06037920116 06 037 920116 9201.16 Census Tract 9201.16 G5020 S 7423211.0 1353.0 +34.4800598 -118.6328670 POLYGON ((-118.65812 34.474675, -118.657839 34... 0.000000 1 -5.338555
14000US06037920314 06 037 920314 9203.14 Census Tract 9203.14 G5020 S 11358678.0 1533.0 +34.4030093 -118.5248234 POLYGON ((-118.543794 34.414228, -118.543012 3... 0.178862 246 0.166776
14000US06037920329 06 037 920329 9203.29 Census Tract 9203.29 G5020 S 2196951.0 0.0 +34.4105552 -118.5503607 POLYGON ((-118.562589 34.419655, -118.562492 3... 0.500000 32 -1.872820
14000US06037920331 06 037 920331 9203.31 Census Tract 9203.31 G5020 S 1505113.0 0.0 +34.3971022 -118.5453610 POLYGON ((-118.553043 34.396256, -118.552819 3... 0.000000 1 -5.338555
14000US06037920334 06 037 920334 9203.34 Census Tract 9203.34 G5020 S 2780846.0 21085.0 +34.3873773 -118.5672498 POLYGON ((-118.571378 34.394062, -118.571056 3... 0.400000 5 -3.729118
14000US06037980008 06 037 980008 9800.08 Census Tract 9800.08 G5020 S 3369326.0 0.0 +34.2106317 -118.4906762 POLYGON ((-118.502667 34.221208, -118.501593 3... 0.428571 7 -3.392645
14000US06037980009 06 037 980009 9800.09 Census Tract 9800.09 G5020 S 20912227.0 356888.0 +34.1276072 -118.2963873 POLYGON ((-118.337072 34.141602, -118.336165 3... 0.500000 2 -4.645408
14000US06037980014 06 037 980014 9800.14 Census Tract 9800.14 G5020 S 6478839.0 973261.0 +33.7824778 -118.2384201 POLYGON ((-118.260881 33.768504, -118.260288 3... 0.355932 59 -1.261018
14000US06037980015 06 037 980015 9800.15 Census Tract 9800.15 G5020 S 5188936.0 220674.0 +33.7732472 -118.2888391 POLYGON ((-118.310477 33.766853, -118.310228 3... 0.333333 12 -2.853649
14000US06037980021 06 037 980021 9800.21 Census Tract 9800.21 G5020 S 6380469.0 565373.0 +34.2700470 -118.3813338 POLYGON ((-118.401829 34.265091, -118.401779 3... 0.333333 3 -4.239943
14000US06037980023 06 037 980023 9800.23 Census Tract 9800.23 G5020 S 2863946.0 2355864.0 +34.2367861 -118.6324389 POLYGON ((-118.648695 34.231201, -118.648031 3... 0.000000 1 -5.338555
14000US06037980024 06 037 980024 9800.24 Census Tract 9800.24 G5020 S 7998854.0 288250.0 +34.1803242 -118.4883751 POLYGON ((-118.518491 34.183893, -118.518487 3... 0.274194 124 -0.518274
14000US06037980026 06 037 980026 9800.26 Census Tract 9800.26 G5020 S 13858036.0 35273.0 +34.2734829 -118.2633094 POLYGON ((-118.351732 34.280342, -118.351731 3... 0.000000 12 -2.853649
14000US06037980028 06 037 980028 9800.28 Census Tract 9800.28 G5020 S 17299747.0 2367417.0 +33.9421429 -118.4173296 POLYGON ((-118.452459 33.943151, -118.446436 3... 0.125000 8 -3.259114
14000US06037980031 06 037 980031 9800.31 Census Tract 9800.31 G5020 S 12492183.0 13434637.0 +33.7390903 -118.2585391 POLYGON ((-118.291048 33.753779, -118.290498 3... 0.555556 9 -3.141331

942 rows × 15 columns


In [23]:
df


Out[23]:
geoid survey_year survey_type year birth_year age gender sex ethnicity race_full ... physical_disability mental_illness alcohol_abuse drug_abuse drug_alcohol_history hiv_positive part_time full_time unemployed_looking unemployed_not_looking
0 NaN Unsheltered 2011 unsheltered 2011 1993.0 18.0 Female F European American White ... 0 0 0.0 0.0 1 0 0.0 0.0 1.0 0.0
1 NaN Unsheltered 2011 unsheltered 2011 1964.0 46.0 Female F African American Black-African-American ... 0 1 0.0 0.0 0 0 0.0 0.0 1.0 0.0
2 NaN Unsheltered 2011 unsheltered 2011 1956.0 55.0 Male M European American White ... 1 0 0.0 0.0 0 0 0.0 0.0 1.0 0.0
3 NaN Unsheltered 2011 unsheltered 2011 1960.0 50.0 Male M European American White ... 0 0 1.0 0.0 1 0 0.0 0.0 1.0 0.0
4 NaN Unsheltered 2011 unsheltered 2011 1979.0 31.0 Male M Latino BLANK ... 0 0 0.0 0.0 0 0 0.0 0.0 1.0 0.0
5 NaN Unsheltered 2011 unsheltered 2011 1952.0 59.0 Male M Unknown BLANK ... 0 0 1.0 0.0 1 0 0.0 0.0 1.0 0.0
6 NaN Unsheltered 2011 unsheltered 2011 1988.0 22.0 Male M African American Black-African-American ... 0 0 0.0 1.0 1 0 0.0 0.0 1.0 0.0
7 NaN Unsheltered 2011 unsheltered 2011 1961.0 49.0 Male M African American Black-African-American ... 0 0 0.0 0.0 0 0 0.0 0.0 1.0 0.0
8 NaN Unsheltered 2011 unsheltered 2011 1981.0 29.0 Male M European American White ... 0 0 0.0 0.0 1 0 0.0 0.0 1.0 0.0
9 NaN Unsheltered 2011 unsheltered 2011 1956.0 55.0 Male M Latino BLANK ... 0 0 0.0 0.0 0 0 0.0 0.0 1.0 0.0
10 NaN Unsheltered 2011 unsheltered 2011 1992.0 18.0 Male M Latino BLANK ... 0 0 0.0 0.0 0 0 0.0 0.0 1.0 0.0
11 NaN Unsheltered 2011 unsheltered 2011 1989.0 21.0 Male M Latino BLANK ... 0 0 0.0 1.0 1 0 0.0 0.0 1.0 0.0
12 NaN Unsheltered 2011 unsheltered 2011 1989.0 21.0 Male M Latino BLANK ... 1 1 1.0 1.0 1 0 0.0 0.0 1.0 0.0
13 NaN Unsheltered 2011 unsheltered 2011 1984.0 26.0 Male M Latino BLANK ... 0 0 0.0 1.0 1 0 0.0 0.0 1.0 0.0
14 NaN Unsheltered 2011 unsheltered 2011 1983.0 27.0 Male M Latino BLANK ... 0 0 0.0 0.0 0 0 0.0 0.0 1.0 0.0
15 NaN Unsheltered 2011 unsheltered 2011 1982.0 28.0 Male M Latino BLANK ... 0 0 1.0 1.0 1 0 0.0 0.0 1.0 0.0
16 NaN Unsheltered 2011 unsheltered 2011 1981.0 29.0 Male M Latino BLANK ... 0 0 1.0 1.0 1 0 0.0 0.0 1.0 0.0
17 NaN Unsheltered 2011 unsheltered 2011 1981.0 29.0 Male M Latino BLANK ... 0 0 0.0 0.0 0 0 0.0 0.0 1.0 0.0
18 NaN Unsheltered 2011 unsheltered 2011 1980.0 30.0 Male M Latino BLANK ... 0 0 0.0 0.0 0 0 0.0 0.0 1.0 0.0
19 NaN Unsheltered 2011 unsheltered 2011 1979.0 31.0 Male M Latino BLANK ... 0 0 1.0 0.0 1 0 0.0 0.0 1.0 0.0
20 NaN Unsheltered 2011 unsheltered 2011 1979.0 31.0 Male M Latino BLANK ... 0 0 0.0 0.0 1 0 0.0 0.0 1.0 0.0
21 NaN Unsheltered 2011 unsheltered 2011 1978.0 32.0 Male M Latino BLANK ... 0 0 0.0 1.0 1 0 0.0 0.0 1.0 0.0
22 NaN Unsheltered 2011 unsheltered 2011 1973.0 37.0 Female F Latino BLANK ... 0 0 0.0 0.0 0 0 0.0 0.0 1.0 0.0
23 NaN Unsheltered 2011 unsheltered 2011 1974.0 37.0 Male M Unknown BLANK ... 0 0 0.0 1.0 1 0 0.0 0.0 1.0 0.0
24 NaN Unsheltered 2011 unsheltered 2011 1973.0 37.0 Male M Latino BLANK ... 0 0 0.0 0.0 0 0 0.0 0.0 1.0 0.0
25 NaN Unsheltered 2011 unsheltered 2011 1972.0 38.0 Male M Latino BLANK ... 0 0 0.0 0.0 0 0 0.0 0.0 1.0 0.0
26 NaN Unsheltered 2011 unsheltered 2011 1971.0 39.0 Male M Latino BLANK ... 0 0 1.0 0.0 1 0 0.0 0.0 1.0 0.0
27 NaN Unsheltered 2011 unsheltered 2011 1970.0 40.0 Male M Latino BLANK ... 0 0 0.0 0.0 0 0 0.0 0.0 1.0 0.0
28 NaN Unsheltered 2011 unsheltered 2011 1969.0 41.0 Unknown U Latino BLANK ... 0 0 0.0 0.0 1 0 0.0 0.0 1.0 0.0
29 NaN Unsheltered 2011 unsheltered 2011 1969.0 41.0 Female F Latino BLANK ... 0 0 0.0 0.0 0 0 0.0 0.0 1.0 0.0
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
73123 14000US06037206300 Sheltered 2017 sheltered 2017 1972.0 45.0 Male M African American African American ... 0 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73124 14000US06037206300 Sheltered 2017 sheltered 2017 1965.0 52.0 Female F Latino European American ... 1 1 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73125 14000US06037206300 Sheltered 2017 sheltered 2017 1981.0 36.0 Male M African American African American ... 1 1 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73126 14000US06037208610 Sheltered 2017 sheltered 2017 1994.0 23.0 Female F Latino European American ... 0 0 0.0 0.0 0 0 1.0 0.0 0.0 0.0
73127 14000US06037208610 Sheltered 2017 sheltered 2017 2010.0 7.0 Male M Latino Refused ... 0 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73128 14000US06037208610 Sheltered 2017 sheltered 2017 1995.0 22.0 Female F Latino Refused ... 0 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73129 14000US06037208610 Sheltered 2017 sheltered 2017 1995.0 22.0 Female F African American African American ... 0 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73130 14000US06037208610 Sheltered 2017 sheltered 2017 2017.0 0.0 Female F African American African American ... 0 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73131 14000US06037208610 Sheltered 2017 sheltered 2017 1997.0 20.0 Female F Other Ethnicity Multi-Race ... 0 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73132 14000US06037208610 Sheltered 2017 sheltered 2017 2016.0 1.0 Male M Latino Multi-Race ... 0 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73133 14000US06037601401 Sheltered 2017 sheltered 2017 1983.0 34.0 Male M African American African American ... 0 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73134 14000US06037206300 Sheltered 2017 sheltered 2017 1967.0 50.0 Unknown U Unknown Null ... 0 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73135 14000US06037408301 Sheltered 2017 sheltered 2017 1953.0 64.0 Unknown U Unknown Null ... 0 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73136 14000US06037206300 Sheltered 2017 sheltered 2017 1960.0 57.0 Unknown U Unknown Null ... 0 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73137 14000US06037232500 Sheltered 2017 sheltered 2017 1988.0 29.0 Female F African American African American ... 0 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73138 14000US06037232500 Sheltered 2017 sheltered 2017 2012.0 5.0 Male M African American African American ... 0 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73139 14000US06037234502 Sheltered 2017 sheltered 2017 NaN NaN Unknown U Unknown Null ... 0 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73140 14000US06037234502 Sheltered 2017 sheltered 2017 1995.0 22.0 Male M African American African American ... 0 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73141 14000US06037209102 Sheltered 2017 sheltered 2017 1979.0 38.0 Male M Unknown Refused ... 0 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73142 14000US06037206300 Sheltered 2017 sheltered 2017 1966.0 51.0 Female F European American European American ... 1 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73143 14000US06037208302 Sheltered 2017 sheltered 2017 1963.0 54.0 Female F African American African American ... 0 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73144 14000US06037900504 Sheltered 2017 sheltered 2017 1975.0 42.0 Male M African American African American ... 1 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73145 14000US06037208302 Sheltered 2017 sheltered 2017 1977.0 40.0 Female F African American African American ... 0 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73146 14000US06037208302 Sheltered 2017 sheltered 2017 1952.0 65.0 Unknown U Unknown Null ... 0 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73147 14000US06037235201 Sheltered 2017 sheltered 2017 1955.0 62.0 Female F European American European American ... 0 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73148 14000US06037503105 Sheltered 2017 sheltered 2017 1996.0 21.0 Female F Latino Don't Know ... 0 0 0.0 0.0 0 0 1.0 0.0 0.0 0.0
73149 14000US06037191000 Sheltered 2017 sheltered 2017 2003.0 14.0 Female F Latino European American ... 0 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73150 14000US06037503105 Sheltered 2017 sheltered 2017 1994.0 23.0 Female F African American African American ... 0 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73151 14000US06037206200 Sheltered 2017 sheltered 2017 1965.0 52.0 Male M African American African American ... 0 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0
73152 14000US06037206300 Sheltered 2017 sheltered 2017 1957.0 60.0 Male M African American African American ... 1 0 0.0 0.0 0 0 0.0 0.0 0.0 0.0

73153 rows × 33 columns


In [24]:
df.head().T


Out[24]:
0 1 2 3 4
geoid NaN NaN NaN NaN NaN
survey_year Unsheltered 2011 Unsheltered 2011 Unsheltered 2011 Unsheltered 2011 Unsheltered 2011
survey_type unsheltered unsheltered unsheltered unsheltered unsheltered
year 2011 2011 2011 2011 2011
birth_year 1993 1964 1956 1960 1979
age 18 46 55 50 31
gender Female Female Male Male Male
sex F F M M M
ethnicity European American African American European American European American Latino
race_full White Black-African-American White White BLANK
race_recode European American African American European American European American Unknown
raceeth nhwhite black nhwhite nhwhite hisp
veteran 0 0 0 1 0
chronic_time 0 0 1 1 0
chronic_condition 0 1 1 1 0
chronic 0 0 1 1 0
adult_with_child 0 0 0 0 0
times_homeless_3yrs 2 to 3 times unknown 1 time 1 time 2 to 3 times
times_homeless_past_year 1 time 2 to 3 times 1 time 4 or more times 1 time
current_stint_duration 4-11 months 4-11 months 12+ months 12+ months 1-3 months
spa 4 6 4 6 6
census_tract NaN NaN NaN NaN NaN
physical_sexual_abuse 0 0 0 0 0
physical_disability 0 0 1 0 0
mental_illness 0 1 0 0 0
alcohol_abuse 0 0 0 1 0
drug_abuse 0 0 0 0 0
drug_alcohol_history 1 0 0 1 0
hiv_positive 0 0 0 0 0
part_time 0 0 0 0 0
full_time 0 0 0 0 0
unemployed_looking 1 1 1 1 1
unemployed_not_looking 0 0 0 0 0

In [29]:
df.groupby(['sex', 'adult_with_child']).mean()['drug_abuse'].unstack() * 100.0


Out[29]:
adult_with_child 0 1
sex
F 11.638346 7.314815
M 13.938345 5.454545
U 14.843007 0.000000

In [ ]: