# AUTOGENERATED! DO NOT EDIT! File to edit: notebooks/Infousa.ipynb (unless otherwise specified).

__all__ = ['totemp', 'totemp', 'totemp', 'totemp', 'sml', 'smlbus', 'smlbus', 'smlbus', 'smlbus', 'smlbus', 'smlbus',
           'smlbus', 'smlbus', 'biz1', 'biz1', 'biz1', 'biz1', 'biz1', 'biz2', 'biz2', 'biz2', 'biz2', 'biz2', 'biz4',
           'biz4', 'biz4', 'biz4', 'biz4', 'neiind', 'neiind', 'neiind', 'neiind', 'neiind', 'neiind', 'neibus',
           'neibus', 'neibus', 'neibus', 'neibus', 'neibus', 'neiemp', 'neiemp', 'neiemp', 'neiemp', 'neiemp', 'neiemp']

# Cell
infoUsaCsaTotals.to_csv('numbus18.csv', index=False)

# Cell
# Aggregate Numeric Values by Sum
totemp = infoUsaCsa.groupby('CSA2010')[ ['CSA2010','empl_size'] ].sum(numeric_only=True)
totemp = totemp.merge( csa[ ['CSA2010','tpop10'] ], left_on='CSA2010', right_on='CSA2010' )
totemp = totemp.append( {'CSA2010': 'Baltimore City' , 'tpop10' : 620961, 'empl_size': totemp['empl_size'].sum() }, ignore_index=True)
totemp['totemp'] = totemp['empl_size']
totemp = totemp.drop('empl_size', axis=1)
totemp.tail()

# Cell
sml = infoUsaCsa.copy()
smlbus = sml[ ( sml['empl_rng'].isin(['1 to 4']) ) ]
smlbus.to_csv('smlbus_empl_rng1 to 4.csv')
print('empl_rng 1 to 4: ', smlbus.size / len(smlbus.columns) )

# Cell
smlbus = sml[ ( sml['empl_rng'].isin(['5 to 9']) ) ]
smlbus.to_csv('smlbus_empl_rng5 to 9.csv')
print('empl_rng 5 to 9: ', smlbus.size / len(smlbus.columns) )

# Cell
smlbus = sml[ ( sml['empl_rng'].isin(['10 to 19']) ) ]
smlbus.to_csv('smlbus_empl_rng10 to 19.csv')
print('empl_rng 10 to 19: ', smlbus.size / len(smlbus.columns) )

# Cell
smlbus = sml[ ( sml['empl_rng'].isin(['20 to 49']) ) ]
smlbus.to_csv('smlbus_empl_rng20 to 49.csv')
print('empl_rng 20 to 49: ', smlbus.size / len(smlbus.columns) )

# Cell
# Filter for small businesses
smlbus = sml[ ( sml['empl_rng'].isin(['1 to 4', '5 to 9',  '10 to 19', '20 to 49']) ) ]
smlbus.to_csv('smlbus18_filtered_points.csv')
print('empl_rng 1 to 49: ', smlbus.size / len(smlbus.columns) )

# Cell
# Aggregate Numeric Values by Sum
smlbus['smlbus'] = 1
smlbus = smlbus.groupby('CSA2010')[ ['CSA2010','smlbus'] ].sum(numeric_only=True)
smlbus = smlbus.merge( csa[ ['CSA2010','tpop10'] ], left_on='CSA2010', right_on='CSA2010' )
smlbus = smlbus.append( {'CSA2010': 'Baltimore City' , 'tpop10' : 620961, 'smlbus': gdf2['smlbus'].sum() }, ignore_index=True)
smlbus.tail()

# Cell
# 145 -biz1XX

# Filter for small businesses
biz1 = infoUsaCsa[ ( infoUsaCsa['first_year'].isin( ['2018'] ) ) ]
print('Count: first_year == 2018: ', biz1.size / len(biz1.columns) )
biz1 = biz1[ ['CSA2010'] ]
#numerator.to_csv('biz18_numerator_csasWithCounts.csv')
biz1['biz1Count'] = 1

# Cell
# Aggregate Numeric Values by Sum
biz1 = biz1.groupby('CSA2010').sum(numeric_only=True)
biz1 = biz1.merge( csa[ ['CSA2010','tpop10'] ], left_on='CSA2010', right_on='CSA2010' )
biz1 = biz1.append( {'CSA2010': 'Baltimore City' , 'tpop10' : 620961, 'biz1Count': biz1['biz1Count'].mean() }, ignore_index=True)
biz1.tail(1)

# Cell
# Create the Indicator
biz1['biz1'] = biz1['biz1Count'] / infoUsaCsaTotals['numbus']
biz1.head()

# Cell
# 151 - biz2XX

# Filter for small businesses
biz2 = infoUsaCsa[ ( infoUsaCsa['first_year'].isin( ['2016', '2017', '2018'] ) ) ]
print('Count: first_year == 2018, 2017, 2016: ', biz2.size / len(biz2.columns) )
biz2 = biz2[ ['CSA2010'] ]
#numerator.to_csv('biz18_numerator_csasWithCounts.csv')
biz2['biz2Count'] = 1

# Cell
# Aggregate Numeric Values by Sum
biz2 = biz2.groupby('CSA2010').sum(numeric_only=True)
biz2 = biz2.merge( csa[ ['CSA2010','tpop10'] ], left_on='CSA2010', right_on='CSA2010' )
biz2 = biz2.append( {'CSA2010': 'Baltimore City' , 'tpop10' : 620961, 'biz2Count': biz2['biz2Count'].mean() }, ignore_index=True)
biz2.tail(1)

# Cell
# 152 - biz4XX

# Filter for small businesses
biz4 = infoUsaCsa[ ( infoUsaCsa['first_year'].isin( ['2015', '2016', '2017', '2018'] ) ) ]
print('Count: first_year == 2018, 2017, 2016, 2015: ', biz2.size / len(biz2.columns) )
biz4 = biz4[ ['CSA2010'] ]
#numerator.to_csv('biz18_numerator_csasWithCounts.csv')
biz4['biz4Count'] = 1

# Cell
# Aggregate Numeric Values by Sum
biz4 = biz4.groupby('CSA2010').sum(numeric_only=True)
biz4 = biz4.merge( csa[ ['CSA2010','tpop10'] ], left_on='CSA2010', right_on='CSA2010' )
biz4 = biz4.append( {'CSA2010': 'Baltimore City' , 'tpop10' : 620961, 'biz4Count': biz4['biz4Count'].mean() }, ignore_index=True)
biz4.tail(1)

# Cell
# 157 - neiindXX

# Filter for small businesses
neiind = infoUsaCsa.copy()
neiind['naics_extra_short'] = neiind.prim_naics.astype(str).str[:-6].astype(np.int64)
neiind = infoUsaCsa[ ( neiind['naics_extra_short'].isin( [44, 45, 52, 54, 62, 71, 72, 81] ) ) ]
print('Count of Naics Starting With: 44, 45, 52, 54, 62, 71, 72, 81: ', neiind.size / len(neiind.columns) )
neiind = neiind[ ['CSA2010'] ]
#numerator.to_csv('biz18_numerator_csasWithCounts.csv')
neiind['neiind'] = 1

# Cell
# Aggregate Numeric Values by Sum
neiind = neiind.groupby('CSA2010').sum(numeric_only=True)
neiind = neiind.merge( csa[ ['CSA2010','tpop10'] ], left_on='CSA2010', right_on='CSA2010' )
neiind = neiind.append( {'CSA2010': 'Baltimore City' , 'tpop10' : 620961, 'neiind': neiind['neiind'].sum() }, ignore_index=True)
neiind.tail(1)

# Cell
# 158 - neibus

# Filter for small businesses
neibus = infoUsaCsa.copy()
neibus['naics_extra_short'] = neibus.prim_naics.astype(str).str[:-6].astype(np.int64)
neibus = infoUsaCsa[ ( neibus['naics_extra_short'].isin( [44, 45, 52, 54, 62, 71, 72, 81] ) ) ]
print('Count of Naics Starting With: 44, 45, 52, 54, 62, 71, 72, 81: ', neibus.size / len(neibus.columns) )
neibus = neibus[ ['CSA2010'] ]
#numerator.to_csv('biz18_numerator_csasWithCounts.csv')
neibus['neibus'] = 1
neibus.head()

# Cell
# Aggregate Numeric Values by Sum
neibus = neibus.groupby('CSA2010').sum(numeric_only=True)
neibus = neibus.merge( csa[ ['CSA2010','tpop10'] ], left_on='CSA2010', right_on='CSA2010' )
neibus = neibus.append( {'CSA2010': 'Baltimore City' , 'tpop10' : 620961, 'neibus': neibus['neibus'].sum() }, ignore_index=True)
neibus['neibus'] = neibus['neibus'] * 1000 / neibus['tpop10']
neibus.tail(1)

# Cell
# 159 - neiempXX

# Filter for small businesses
neiemp = infoUsaCsa.copy()
neiemp['naics_extra_short'] = neiemp.prim_naics.astype(str).str[:-6].astype(np.int64)
neiemp = infoUsaCsa[ ( neiemp['naics_extra_short'].isin( [44, 45, 52, 54, 62, 71, 72, 81] ) ) ]
print('Count of Naics Starting With: 44, 45, 52, 54, 62, 71, 72, 81: ', neiemp.size / len(neiemp.columns) )
#numerator.to_csv('biz18_numerator_csasWithCounts.csv')

# Cell
# Aggregate Numeric Values by Sum
neiemp = neiemp.groupby('CSA2010')[ ['CSA2010','empl_size'] ].sum(numeric_only=True)
neiemp = neiemp.merge( csa[ ['CSA2010','tpop10'] ], left_on='CSA2010', right_on='CSA2010' )
neiemp = neiemp.append( {'CSA2010': 'Baltimore City' , 'tpop10' : 620961, 'empl_size': neiemp['empl_size'].sum() }, ignore_index=True)
neiemp['neiemp'] = neiemp['empl_size']
neiemp = neiemp.drop('empl_size', axis=1)
neiemp.tail()