<jupyter_start><jupyter_text>"Housing Insecurity DataDive:  eviction rates for years 2017, 1018, 2019 in NYC <EMAIL>, github: mishide<jupyter_code>import pandas as pd
import seaborn as sns
# Read in processed data
nyc_ts_processed = pd.read_csv("../../data/processed/nyc_processed_timeseries_2017_to_2019_20210225.csv")<jupyter_output><empty_output><jupyter_text>(NYC) How many total evictions were there in 2017?, 2018?, 2019?  What is the percent change between each year? Steady decreases in evictions are seen from 2017 thru 2019 Decrease in 2019 that was over 4 times that of 2018.<jupyter_code># Function returns Total evictions by year

def total_evictions(df, begin, end, year):
    df_year = df[(df["month"] > begin) & (df["month"] < end)]
    print("The year", year, "experienced ", df_year["total-eviction-filings"].sum(),"evictions in NYC")
    return df_year["total-eviction-filings"].sum()
no_2017 = total_evictions(nyc_ts_processed, "2016-12", "2018-01", 2017)
no_2018 = total_evictions(nyc_ts_processed, "2017-12", "2019-01", 2018)
no_2019 = total_evictions(nyc_ts_processed, "2018-12", "2020-01", 2019)
# Calcualte percent change over years 2017-18 and 2018-19

change_2018 = 100*((no_2018-no_2017)/no_2017)
change_2019 = 100*((no_2019-no_2018)/no_2018)
print("Percent change from 2017 to 2018 was ", change_2018)
print("Percent change from 2018 to 2019 was ", change_2019)
# Plot of the eviction rate drop
sns.set(rc={'figure.figsize':(6,7)})
df = pd.DataFrame({'Percent Change Over Years':["2017-18", "2018-19"], 'Percent Change':[change_2018, change_2019]})
ax = df.plot.bar(x='Percent Change Over Years', y='Percent Change', rot=0)<jupyter_output><empty_output><jupyter_text>(NYC) What is the overall eviction rate for this time period (i.e., evictions/renting households)? The overall eviction rate from 2017 through 2019 was 2.7%<jupyter_code># Read in the eviction data

nyc_processed = pd.read_csv('../../data/processed/nyc_processed_2017_to_2019_20210225.csv')
# Calculates the overall eviction rate for 2017-19

print("The overall eviction rate from Jan 2017 through Dec 2019 was", 100 *( (no_2017+no_2018+no_2019)/(nyc_processed['total-renter-occupied-households'].sum()) ))<jupyter_output>The overall eviction rate from Jan 2017 through Dec 2019 was 2.713904673111517<jupyter_text>From the graph we see the clear and consistent drop in evictions started near September 2018.   There may have been a change around that time frame resulting in reduced eviction rates worth exploring.<jupyter_code># Read in and prep the dataframe for plot

nyc_ts_processed = pd.read_csv("../../data/processed/nyc_processed_timeseries_2017_to_2019_20210225.csv")

nyc_ts_processed["year"] = 0      #add column to df
df = nyc_ts_processed             #name change for ease of use

# Fill 'year' column
df.loc[df['month'] < '2018-01', 'year'] = 2017
df.loc[(df['month'] < '2019-01') & (df['month'] > '2017-12'), 'year'] = 2018
df.loc[(df['month'] < '2020-01') & (df['month'] > '2018-12'), 'year'] = 2019<jupyter_output><empty_output><jupyter_text>Yearly comparison of Total Evictions by month<jupyter_code># Plot Years by monthly eviction rates
sns.set(rc={'figure.figsize':(14,9)})
sns.lineplot(data=df, x= df['month'].str[-2:], y="total-eviction-filings", hue = "year", palette='tab10')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13349368610944076, 'fraction_numerical': 0.10883944678292243, 'mean_word_length': 5.989495798319328, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '57073', 'license': 'MIT', 'n_tokens_mistral': 1415, 'n_tokens_neox': 1098, 'n_words': 316, 'path': 'scripts/_mide/NYC_EvictionRates.ipynb', 'repo_name': 'datakind/Mar21-housing-insecurity', 'size': '3341'}