{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Map of King County Real Estate by Zipcode\n", "\n", "Continuation of *3.2 Geospatial Mapping* in [Main Notebook](https://github.com/czarinagluna/regression-analysis-for-estimating-prices/blob/main/main.ipynb)\n", "\n", "*** \n", "**By [Czarina Luna](https://www.linkedin.com/in/czarinagluna/)**" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%store -r UnderMillion" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "%store -r OverMillion" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Please use the [notebook viewer](https://nbviewer.org/github/czarinagluna/regression-analysis-for-estimating-prices/blob/main/map.ipynb) to render the maps.**" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "scrolled": true }, "outputs": [], "source": [ "import folium as folium\n", "\n", "def map_zipcode(data, title, color, name):\n", " '''Maps the data points according to price per zipcode in King County'''\n", " king_county_geo = 'data/map/Zipcodes_for_King_County_and_Surrounding_Area___zipcode_area.geojson'\n", "\n", " king_county_map = folium.Map(location=[47.484823, -122.112342], tiles='cartodbpositron', zoom_start=9.5)\n", "\n", " folium.Choropleth(\n", " geo_data=king_county_geo,\n", " data=data,\n", " columns=['zipcode', 'price'],\n", " key_on='feature.properties.ZIP',\n", " fill_color=color,\n", " fill_opacity=0.7,\n", " line_opacity=0.2,\n", " legend_name=title).add_to(king_county_map)\n", "\n", " folium.LayerControl().add_to(king_county_map)\n", " king_county_map.save(name)\n", " return king_county_map\n", "\n", "import warnings\n", "warnings.filterwarnings('ignore')" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "map_zipcode(UnderMillion, 'House Prices Sold Under $1 Million', 'PuBuGn', 'data/images/UnderMillion.html')" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Make this Notebook Trusted to load map: File -> Trust Notebook
" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "map_zipcode(OverMillion, 'House Prices Sold Over $1 Million', 'Greens', 'data/images/OverMillion.html')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Contact\n", "\n", "Feel free to contact me for any questions and connect with me on [Linkedin](https://www.linkedin.com/in/czarinagluna/)." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }