<jupyter_start><jupyter_text>What influences home value more weather or location?  Data Collection Plan - Census Data - First I collected census data for median income and median home value for every county in the US - Then I edited the census CVS's in Excel to get rid of unnessecary rows and ID columns. I also added columns to break out county name and state into 2 columns. - I then imported all of the data from the census to combine all of the housing and income data into one data set, this was then exported a CSV in to the Input Files folder as Income and Housing Data. - I also exported a CSV that just included state and county information to the Interim Files Folder to use with the Google geolocation API.<jupyter_code># refine housing and income data by selecting relevant columns and renaming columns

median_income = median_income[["Geography","County","state","Mean income (dollars); Estimate; All households"]]
median_income = median_income.rename(columns={"state":"State","Mean income (dollars); Estimate; All households":"Median Income"})

median_home_value_acs = median_home_value_acs[["Geography","Estimate; Median value (dollars)"]]
median_home_value_acs = median_home_value_acs.rename(columns={"Estimate; Median value (dollars)":"ACS Home Value"})

zillow_home_value = zillow_home_value[["geography","Zhvi"]]
zillow_home_value = zillow_home_value.rename(columns={"geography":"Geography","Zhvi":"Zillow Home Value"})

zillow_bottom_tier = zillow_bottom_tier[["Geography","2018-12"]]
zillow_bottom_tier = zillow_bottom_tier.rename(columns={"2018-12":"Zillow Bottom Tier Home Value"})

zillow_top_tier = zillow_top_tier[["Geography","2018-12"]]
zillow_top_tier = zillow_top_tier.rename(columns={"2018-12":"Zillow Top Tier Home Value"})

# create a csv for the county and state data

output_data = median_income[["Geography","County","State"]]

output_data.to_csv("./Interim Data Files/State and County Info.csv", index=False, header=True)<jupyter_output><empty_output><jupyter_text>Data Collection Plan - Google API for Lat and Long - I then imported the state and county data into the Get Lat and Lng for Counties jupyter notebook and made calls to the Google geocode API to collect latitude and longitude data. I exported a CSV to Interim Data Files to use with the weather data API.<jupyter_code>from config import gkey

locations = pd.read_csv("Interim Data Files/State and County Info.csv")

locations['Latitude'] = ""
locations['Longitude'] = ""

# Build URL using the Google MAps API

base_url = "https://maps.googleapis.com/maps/api/geocode/json?"

location=""

params={
    "key": gkey
}

# iterate through datafram and retrieve lat and lng info

for index, row in locations.iterrows():

    location = row['Geography']
    params["address"] = location

    response = requests.get(base_url,params=params).json()
    
    # extract results
    
    results = response['results']
    
    try:
        print(f"Retrieving Results for Index {index}: {location}.")
        
        locations.loc[index, 'Latitude'] = results[0]['geometry']['location']['lat']
        locations.loc[index, 'Longitude'] = results[0]['geometry']['location']['lng']
        
    except (KeyError, IndexError):
        print("Missing field/result... skipping.")
        
    print("------------")<jupyter_output><empty_output><jupyter_text>Data Collection Plan - aWhere API - I then used the state and county daya with latitude and longitude to make API calls to aWhere's Historical Norms API to collect weather data for each county. I exported a CSV to Input Data to use in my final analysis.<jupyter_code>locations = pd.read_csv("Interim Data Files/State and County Info with Lat and Lng.csv")

locations['Avg Temperature'] = ""
locations['Max Temperature'] = ""
locations['Min Temperature'] =  ""
locations['Avg Percipitation'] = ""
locations['Min Humidity'] = ""
locations['Max Humidity'] = ""
locations['Avg Wind'] = ""

url = "https://api.awhere.com/v2/weather/locations"

lat = ""
lng = ""

headers = {"Authorization": "Bearer " + access_token}

#loop through rows, make API calls and store data

for index, row in locations.iterrows():
    lat = row['Latitude']
    lng = row['Longitude']

    query_url = f"{url}/{lat},{lng}/norms/01-01/years/2015,2018/?&units=usa"
    
    response = requests.get(query_url, headers=headers)
    response_json = response.json()
    
    try:
        print(f"Retrieving Results for Index {index}")
        
        locations.loc[index, 'Avg Temperature'] = response_json['meanTemp']['average']
        locations.loc[index, 'Max Temperature'] = response_json['maxTemp']['average']
        locations.loc[index, 'Min Temperature'] = response_json['minTemp']['average']
        locations.loc[index, 'Avg Percipitation'] = response_json['precipitation']['average']
        locations.loc[index, 'Min Humidity'] = response_json['minHumidity']['average']
        locations.loc[index, 'Max Humidity'] = response_json['maxHumidity']['average']
        locations.loc[index, 'Avg Wind'] = response_json['averageWind']['average']
        
    except (KeyError, IndexError):
        print("Missing field/result... skipping.")
        
    print("------------")<jupyter_output><empty_output><jupyter_text>Data Analysis- I then imported the Income and Housing Data CSV and the Weather Data CSV to the Final Data Cleanup and Plot Generation jupyter notebook. I then merged the data into one data set and generated various graphs to communicate the trends observed in the data. I also exported a CSV and all of my plots to the Output Files Folder.  What influences home value?  Question 1 - Is there a correlation between weather and housing prices?<jupyter_code>from IPython.display import Image
Image("Figures/Med Home Value vs Avg Percip.png")
Image("Figures/Med Home Value vs Avg Wind.png")
Image("Figures/Med Home Value vs Avg Temp.png")
Image("Figures/Med Home Value vs Max Humidity.png")<jupyter_output><empty_output><jupyter_text>Question 1- There seems to be a correlation between rain fall and housing prices, there are hardly counties that have an average home price above 200,000 that have over an average daily rain fall of over .2". - There also seems to be the same kind of relationship between average wind speed and home value. Very few counties with and median home price over 200,000 had an average wind speed over 15 mph. - There is much less of a correlation between temperature and house value, there does seem to be a slight upper limit of around 50 degrees for the average temperature.- There was no observable correlation between humidity and house value.  Question 2 - Is there a correlation between location and housing prices?<jupyter_code>Image("Figures/Best Weather - Med Home Value vs Latitude.png")
Image("Figures/Best Weather - Med Home Value vs Longitude.png")<jupyter_output><empty_output><jupyter_text>Question 2  - When the data is plotted against latitude and longitude vs home value the more expensive counties fell between a latitude of less than 50 greater than 30 and a longitude greater than -80 and less than -100 - The correlations for houing prices seems to be stronger based on location and specifically longitude  Question 3 - What are the least expensive places to live with the nicest weather?<jupyter_code>Image("Figures/Heat Map of Cheapest Counties with the Best Weather and Location.png")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10133765707336846, 'fraction_numerical': 0.009593298202945548, 'mean_word_length': 4.702619414483821, 'pattern_counts': {'":': 9, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 2, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '567095', 'license': 'MIT', 'n_tokens_mistral': 2193, 'n_tokens_neox': 2010, 'n_words': 787, 'path': 'Final Data Analysis.ipynb', 'repo_name': 'jhills5821/Project-1', 'size': '7401'}