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

__all__ = ['faresCsa', 'salepr', 'salepr', 'salepr', 'salepr', 'salepr', 'faresCsa', 'shomes', 'shomes', 'shomes',
           'shomes']

# Cell
# Copy the Data
faresCsa = fares.copy()
faresCsa['SALEDATE'] = pd.to_datetime(faresCsa['SALEDATE'], format='%Y%m%d') # ,infer_datetime_format=True)

# Query the Data
salepr = faresCsa[
  (faresCsa['PROPERTYIN'].str.contains('CONDOMINIUM|SINGLE FAMILY', regex=True) )
& (faresCsa['SALEDATE'] >= '20'+year+'-01-01')
& (faresCsa['SALEDATE'] <= '20'+year+'-12-31')
& (faresCsa['SALEAMOUNT'] > 1000 )
& (faresCsa['PRIMARYCAT'] == 'ARMS LENGTH' )
]

# Prep and Save the Filtered Records
salepr.rename(columns={ 'SALEAMOUNT':'29-salepr'+year}, inplace=True)
salepr.drop(columns=['geometry', 'PRIMARYCAT', 'PROPERTYIN', 'LANDUSECOD', 'SALEDATE' ], inplace=True)
salepr.to_csv('fares_filtered_'+year+'.csv')

# *Special*: # UPDATE HERE AND THEN GROUP
salepr = salepr.append({'CSA2010': 'Baltimore City' , '29-salepr'+year : salepr['29-salepr'+year].median() } , ignore_index=True)
salepr = salepr.groupby('CSA2010').median(numeric_only=True)

# Make sure ALL csas and BaltimoreCity are included and sorted.
salepr = csa.merge( salepr, left_on='CSA2010', right_on='CSA2010', how='outer' )
salepr.drop(columns=['OBJECTID', 'Shape__Length', 'Shape__Area', 'geometry' ], inplace=True)
salepr = salepr[['CSA2010', '29-salepr'+year]]

display( salepr.head(2) )
salepr.tail(2)

salepr.to_csv('29-salepr'+year+'.csv')

# & (faresCsa['PRIMCATCOD'] == 'ARMS LENGTH' )
# faresCsa['LANDUSECOD'].str.contains('HIGH RISE CONDO|CONDOMINIUM|RESIDENTIAL (NEC)|MID RISE CONDO|MULTI FAMILY DWELLING|MULTI FAMILY 10 UNITS LESS|SFR|TOWNHOUSE/ROWHOUSE', regex=False)

# Cell
# Copy the Data
faresCsa = fares.copy()
faresCsa['SALEDATE'] = pd.to_datetime(faresCsa['SALEDATE'], format='%Y%m%d') # ,infer_datetime_format=True)

# Query the Data
shomes = faresCsa[
  (faresCsa['PROPERTYIN'].str.contains('CONDOMINIUM|SINGLE FAMILY', regex=True) )
& (faresCsa['SALEDATE'] >= '20'+year+'-01-01')
& (faresCsa['SALEDATE'] <= '20'+year+'-12-31')
& (faresCsa['SALEAMOUNT'] > 1000 )
& (faresCsa['PRIMARYCAT'] == 'ARMS LENGTH' )
]

# Prep and Save the Filtered Records
shomes['31-shomes'+year] = 1
# shomes.rename(columns={ 'SALEAMOUNT':'29-shomes'+year}, inplace=True)
# shomes.drop(columns=['geometry', 'PRIMARYCAT', 'PROPERTYIN', 'LANDUSECOD', 'SALEDATE', 'SALEAMOUNT'], inplace=True)
shomes = shomes[['CSA2010','31-shomes'+year]]
shomes.to_csv('fares_filtered_'+year+'.csv')

# *Special*: # UPDATE HERE AND THEN GROUP
# shomes = shomes.append({'CSA2010': 'Baltimore City', '31-shomes'+year : shomes['31-shomes'+year].sum() } , ignore_index=True)
shomes = shomes.groupby('CSA2010').sum(numeric_only=True)

# Make sure ALL csas and BaltimoreCity are included and sorted.
shomes = csa.merge( shomes, left_on='CSA2010', right_on='CSA2010', how='outer' )
shomes.drop(columns=['OBJECTID', 'Shape__Length', 'Shape__Area', 'geometry' ], inplace=True)

# *SPECIAL* Update the baltimore CSA.
shomes.at[55] = shomes.sum(numeric_only=True)
shomes.at[55, 'CSA2010'] = 'Baltimore City'

display( shomes.head(2) )
shomes.tail(2)

shomes.to_csv('31-shomes'+year+'.csv')

# & (faresCsa['PRIMCATCOD'] == 'ARMS LENGTH' )
# faresCsa['LANDUSECOD'].str.contains('HIGH RISE CONDO|CONDOMINIUM|RESIDENTIAL (NEC)|MID RISE CONDO|MULTI FAMILY DWELLING|MULTI FAMILY 10 UNITS LESS|SFR|TOWNHOUSE/ROWHOUSE', regex=False)