CI Challenge 2021 - Q4

California 2020 Census data profiling

Sudha Kumar 12/13/21

Source data: California 2020 Census - California_CA.csv file from https://www.kaggle.com/zusmani/us-census-2020/version/3?select=California_CA.csv
File size: 721 MB
669171 x 401 columns

Install packages

Import libraries

Read csv file with pandas

Read csv file with spark

Read csv file with Spark using inferSchema option

Convert Spark dataframe to Koalas dataframe to perform Pandas like operations

Read csv file with Koalas

Koalas is an open-source Python package that implements the pandas API on top of Apache Spark, to make the pandas API scalable to big data.

Time to read 721 MB csv file during one of the runs

Pandas Spark Spark with inferSchema option Koalas
24.44 secs 7.14 secs 5.44 secs 3.22 secs

Selecting 104 columns for analysis

The following 104 columns of data will be used for analysis:

REGION Region
DIVISION Division
COUNTY County (FIPS)
CBSA Metropolitan Statistical Area/Micropolitan Statistical Area
MEMI Metropolitan/Micropolitan Indicator
CSA Combined Statistical Area
METDIV Metropolitan Division
AREALAND Area (Land)
AREAWATR Area (Water)
BASENAME Area Base Name
NAME Area Name-Legal/Statistical Area Description (LSAD) Term-Part Indicator
FUNCSTAT Functional Status Code
POP100 Population Count (100%)
HU100 Housing Unit Count (100%)
INTPTLAT Internal Point (Latitude)
INTPTLON Internal Point (Longitude)
LSADC Legal/Statistical Area Description Code
P0010001 Total:
P0010002 Population of one race:
P0010003 White alone
P0010004 Black or African American alone
P0010005 American Indian and Alaska Native alone
P0010006 Asian alone
P0010007 Native Hawaiian and Other Pacific Islander alone
P0010008 Some Other Race alone
P0010009 Population of two or more races:
P0010010 Population of two races:
P0010011 White; Black or African American
P0010012 White; American Indian and Alaska Native
P0010013 White; Asian
P0010014 White; Native Hawaiian and Other Pacific Islander
P0010015 White; Some Other Race
P0010016 Black or African American; American Indian and Alaska Native
P0010017 Black or African American; Asian
P0010018 Black or African American; Native Hawaiian and Other Pacific Islander
P0010019 Black or African American; Some Other Race
P0010020 American Indian and Alaska Native; Asian
P0010021 American Indian and Alaska Native; Native Hawaiian and Other Pacific Islander
P0010022 American Indian and Alaska Native; Some Other Race
P0010023 Asian; Native Hawaiian and Other Pacific Islander
P0010024 Asian; Some Other Race
P0010025 Native Hawaiian and Other Pacific Islander; Some Other Race
P0010026 Population of three races:
P0010027 White; Black or African American; American Indian and Alaska Native
P0010028 White; Black or African American; Asian
P0010029 White; Black or African American; Native Hawaiian and Other Pacific Islander
P0010030 White; Black or African American; Some Other Race
P0010031 White; American Indian and Alaska Native; Asian
P0010032 White; American Indian and Alaska Native; Native Hawaiian and Other Pacific Islander
P0010033 White; American Indian and Alaska Native; Some Other Race
P0010034 White; Asian; Native Hawaiian and Other Pacific Islander
P0010035 White; Asian; Some Other Race
P0010036 White; Native Hawaiian and Other Pacific Islander; Some Other Race
P0010037 Black or African American; American Indian and Alaska Native; Asian
P0010038 Black or African American; American Indian and Alaska Native; Native Hawaiian and Other Pacific Islander
P0010039 Black or African American; American Indian and Alaska Native; Some Other Race
P0010040 Black or African American; Asian; Native Hawaiian and Other Pacific Islander
P0010041 Black or African American; Asian; Some Other Race
P0010042 Black or African American; Native Hawaiian and Other Pacific Islander; Some Other Race
P0010043 American Indian and Alaska Native; Asian; Native Hawaiian and Other Pacific Islander
P0010044 American Indian and Alaska Native; Asian; Some Other Race
P0010045 American Indian and Alaska Native; Native Hawaiian and Other Pacific Islander; Some Other Race
P0010046 Asian; Native Hawaiian and Other Pacific Islander; Some Other Race
P0010047 Population of four races:
P0010048 White; Black or African American; American Indian and Alaska Native; Asian
P0010049 White; Black or African American; American Indian and Alaska Native; Native Hawaiian and Other Pacific Islander
P0010050 White; Black or African American; American Indian and Alaska Native; Some Other Race
P0010051 White; Black or African American; Asian; Native Hawaiian and Other Pacific Islander
P0010052 White; Black or African American; Asian; Some Other Race
P0010053 White; Black or African American; Native Hawaiian and Other Pacific Islander; Some Other Race
P0010054 White; American Indian and Alaska Native; Asian; Native Hawaiian and Other Pacific Islander
P0010055 White; American Indian and Alaska Native; Asian; Some Other Race
P0010056 White; American Indian and Alaska Native; Native Hawaiian and Other Pacific Islander; Some Other Race
P0010057 White; Asian; Native Hawaiian and Other Pacific Islander; Some Other Race
P0010058 Black or African American; American Indian and Alaska Native; Asian; Native Hawaiian and Other Pacific Islander
P0010059 Black or African American; American Indian and Alaska Native; Asian; Some Other Race
P0010060 Black or African American; American Indian and Alaska Native; Native Hawaiian and Other Pacific Islander; Some Other Race
P0010061 Black or African American; Asian; Native Hawaiian and Other Pacific Islander; Some Other Race
P0010062 American Indian and Alaska Native; Asian; Native Hawaiian and Other Pacific Islander; Some Other Race
P0010063 Population of five races:
P0010064 White; Black or African American; American Indian and Alaska Native; Asian; Native Hawaiian and Other Pacific Islander
P0010065 White; Black or African American; American Indian and Alaska Native; Asian; Some Other Race
P0010066 White; Black or African American; American Indian and Alaska Native; Native Hawaiian and Other Pacific Islander; Some Other Race
P0010067 White; Black or African American; Asian; Native Hawaiian and Other Pacific Islander; Some Other Race
P0010068 White; American Indian and Alaska Native; Asian; Native Hawaiian and Other Pacific Islander; Some Other Race
P0010069 Black or African American; American Indian and Alaska Native; Asian; Native Hawaiian and Other Pacific Islander; Some Other Race
P0010070 Population of six races:
P0010071 White; Black or African American; American Indian and Alaska Native; Asian; Native Hawaiian and Other Pacific Islander; Some Other Race
P0020002 Hispanic or Latino
P0020003 Not Hispanic or Latino:
H0010001 H1-1: Total
H0010002 H1-2: Occupied
H0010003 H1-3: Vacant
P0050001 Total:
P0050002 Institutionalized population:
P0050003 Correctional facilities for adults
P0050004 Juvenile facilities
P0050005 Nursing facilities/Skilled-nursing facilities
P0050006 Other institutional facilities
P0050007 Noninstitutionalized population:
P0050008 College/University student housing
P0050009 Military quarters
P0050010 Other noninstitutional facilities

Subsetting from Spark dataframe

Subsetting from Koalas dataframe

Continuing with Koalas dataframe

Noticing the following issues from the 'describe' table: Some counties have 0 value for POP100 (population count 100%), HU100 (Housing count 100%), H0010001 (Total) ????

Plot population be city / county / school district / census tract

The NAME column has County / City / Block / Census Tract / School District. Separating County data

Plot population distribution by ethnicity in San Diego County

Use Geopandas to show population bubbles on a Map

Institutionalized and non institutionalized population

K Means clustering of institutionalized and non institutionalized population

Based on Elbow method, choosing n_clusters = 4