<jupyter_start><jupyter_text>Housing Rental Analysis for San Francisco<jupyter_code># Imported the required libraries and dependencies
import pandas as pd
import hvplot.pandas
from pathlib import Path
# Used the read_csv function, to create a DataFrame 
sfo_data_df = pd.read_csv('Resources/sfo_neighborhoods_census_data.csv', index_col='year')

# Reviewing the first and last five rows of the DataFrame
display(sfo_data_df.head())
display(sfo_data_df.tail())<jupyter_output><empty_output><jupyter_text>---<jupyter_code># Created a numerical aggregation that groups the data by the year and then averages the results.
housing_units_by_year = sfo_data_df.groupby('year').mean()

# Reviewing the DataFrame
display(housing_units_by_year)
# Created a visual aggregation of the housing units by year
housing_units_by_year.plot.bar(
    y='housing_units',
    figsize=(10,7),
    title='Housing Units Per Year - San Francisco 2010-2016'
)<jupyter_output><empty_output><jupyter_text>**Question:** What is the overall trend in housing_units over the period being analyzed?**Answer:** From 2010-2016 San Francisco saw a steady increase of around 2000 housing units from year to year. ---<jupyter_code># Created a numerical aggregation by grouping the data by year and averaging the results
prices_square_foot_by_year = sfo_data_df.groupby('year').mean()

# Reviewing the DataFrame
display(prices_square_foot_by_year)<jupyter_output><empty_output><jupyter_text>**Question:** What is the lowest gross rent reported for the years included in the DataFrame?**Answer:*** 2010 had the loswest gross rent with an average cost of rent being $1239.00<jupyter_code># Filtered out the housing_units column, created a new DataFrame 
prices_square_foot_by_year = prices_square_foot_by_year[['sale_price_sqr_foot','gross_rent']]

# Reviewing the DataFrame
display(prices_square_foot_by_year)
# Plotted prices_square_foot_by_year. 
prices_square_foot_by_year.hvplot(
    xlabel='Years',
    ylabel='Gross Rent/Sale Price Per Square Foot',
    title='Sale Price Per Square Foot and Average Gross Rent - 2010-2016 - San Francisco',
    rot=90
)<jupyter_output><empty_output><jupyter_text>**Question:** Did any year experience a drop in the average sale price per square foot compared to the previous year?**Answer:** The analysis shows that from 2010-2016 the average sale price per square foor grew year over year and never experienced a drop in price. **Question:** If so, did the gross rent increase or decrease during that year?**Answer:** The gross rent did infact experience a drop in price from 2010-2011 but then continued to increase every year after that. ---<jupyter_code># Grouped by year and neighborhood and then created a new dataframe of the mean values
prices_by_year_by_neighborhood = sfo_data_df.groupby(['neighborhood','year']).mean()

# Reviewing the DataFrame
display(prices_by_year_by_neighborhood)
# Filtered out the housing_units
prices_by_year_by_neighborhood = prices_by_year_by_neighborhood[['sale_price_sqr_foot','gross_rent']]

# Reviewing the first and last five rows of the DataFrame
display(prices_by_year_by_neighborhood.head())
display(prices_by_year_by_neighborhood.tail())
# Useed hvplot to create an interactive line plot of the average price per square foot per neighborhood
prices_by_year_by_neighborhood.hvplot(title='Sale Price Per Square Foot and Average Gross Rent- 2010-2016 - By Neighborhood',
                                      x='year',
                                     groupby='neighborhood'
                                     )<jupyter_output><empty_output><jupyter_text>**Question:** For the Anza Vista neighborhood, is the average sale price per square foot for 2016 more or less than the price that’s listed for 2012? **Answer:** At the start of 2014 Anza Vista's average sale price per square foot started to see a decrease and by the start of 2016 had dropped lower than the price it was as in 2010. ---<jupyter_code># Loaded neighborhoods_coordinates.csv data into a DataFrame
neighborhood_locations_df = pd.read_csv('Resources/neighborhoods_coordinates.csv', index_col='Neighborhood')

# Reviewing the DataFrame
display(neighborhood_locations_df)
# Calculated the mean values for each neighborhood
all_neighborhood_info_df = sfo_data_df.groupby('neighborhood').mean()

# Reviewing the DataFrame
display(all_neighborhood_info_df)
# Used the Pandas `concat` function to join the 
# neighborhood_locations_df and the all_neighborhood_info_df DataFrame
all_neighborhoods_df = pd.concat(
    [neighborhood_locations_df, all_neighborhood_info_df], 
    axis='columns',
    sort=False
)

# Reviewing the DataFrame
display(all_neighborhoods_df.head())
display(all_neighborhoods_df.tail())

# Called the dropna function to remove any neighborhoods that do not have data
all_neighborhoods_df = all_neighborhoods_df.reset_index().dropna()

# Renamed the "index" column as "Neighborhood" for use in the visualization
all_neighborhoods_df = all_neighborhoods_df.rename(columns={'index': 'Neighborhood'})

# Reviewing the resulting DataFrame
display(all_neighborhoods_df.head())
display(all_neighborhoods_df.tail())
# Created a plot to analyze neighborhood info
all_neighborhoods_df.hvplot.points(
    'Lon',
    'Lat',
    geo=True,
    hover_cols='Neighborhood',
    size='sale_price_sqr_foot',
    color='gross_rent',
    tiles='OSM',
    frame_width=700,
    frame_height=500,
    ylabel="Latitude",
    xlabel="Longitude",
    title='Gross Rent and Sale Price Per Square Foot Per Neighborhood - 2010-2016 - San Francisco')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07881067526419487, 'fraction_numerical': 0.018090632276553824, 'mean_word_length': 5.515752625437573, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '345953', 'license': 'ADSL', 'n_tokens_mistral': 1804, 'n_tokens_neox': 1636, 'n_words': 533, 'path': 'san_francisco_housing.ipynb', 'repo_name': 'Surdano/Rental_Market_Analysis', 'size': '5583'}