|
65 | 65 | "import matplotlib.pyplot as plt\n",
|
66 | 66 | "\n",
|
67 | 67 | "\n",
|
68 |
| - "from datetime import datetime\n", |
| 68 | + "from datetime import datetime as dt\n", |
69 | 69 | "import pandas as pd\n",
|
70 | 70 | "import numpy as np\n",
|
71 | 71 | "from IPython.display import display, HTML\n",
|
|
728 | 728 | "source": [
|
729 | 729 | "agg_result = summarize_data.aggregate_points(point_layer=airbnb_layer,\n",
|
730 | 730 | " polygon_layer=nyc_tracts_layer,\n",
|
731 |
| - " output_name='airbnb_counts'+ str(datetime.now().microsecond))" |
| 731 | + " output_name='airbnb_counts'+ str(dt.now().microsecond))" |
732 | 732 | ]
|
733 | 733 | },
|
734 | 734 | {
|
|
1676 | 1676 | "# Data Enriching operation\n",
|
1677 | 1677 | "airbnb_count_by_tract_enriched = enrich_layer(airbnb_count_by_tract,\n",
|
1678 | 1678 | " analysis_variables = variable_names,\n",
|
1679 |
| - " output_name='airbnb_tract_enrich1'+ str(datetime.now().microsecond))" |
| 1679 | + " output_name='airbnb_tract_enrich1'+ str(dt.now().microsecond))" |
1680 | 1680 | ]
|
1681 | 1681 | },
|
1682 | 1682 | {
|
|
4285 | 4285 | " hotels_lyr,\n",
|
4286 | 4286 | " measurement_type='StraightLine',\n",
|
4287 | 4287 | " max_count=1,\n",
|
4288 |
| - " output_name='ny_tract_hotel_dist1' + str(datetime.now().microsecond))" |
| 4288 | + " output_name='ny_tract_hotel_dist1' + str(dt.now().microsecond))" |
4289 | 4289 | ]
|
4290 | 4290 | },
|
4291 | 4291 | {
|
|
5152 | 5152 | "source": [
|
5153 | 5153 | "# Final hotel Distances in feet — Here in each row column \"hotel_dist\" returns the distance of the nearest hotel from that tract indicated by its geoids.\n",
|
5154 | 5154 | "# For example in the first row the tract with ID 36005000100 has a nearest hotel at 5571.75 feet away from it. \n",
|
5155 |
| - "sdf_tract_hotel_dist_lyr_new = sdf_tract_hotel_dist_lyr[['From_geoid', 'Total_Miles']]\n", |
5156 |
| - "sdf_tract_hotel_dist_lyr_new['hotel_dist'] = round(sdf_tract_hotel_dist_lyr_new['Total_Miles'] * 5280, 2)\n", |
| 5155 | + "sdf_tract_hotel_dist_lyr_new = sdf_tract_hotel_dist_lyr[['From_geoid', 'Total_Kilometers']]\n", |
| 5156 | + "sdf_tract_hotel_dist_lyr_new['hotel_dist'] = round(sdf_tract_hotel_dist_lyr_new['Total_Kilometers'] * 3280.84, 2)\n", |
5157 | 5157 | "sdf_tract_hotel_dist_lyr_new.sort_values('From_geoid').head()"
|
5158 | 5158 | ]
|
5159 | 5159 | },
|
|
5168 | 5168 | " bus_stop_lyr,\n",
|
5169 | 5169 | " measurement_type='StraightLine',\n",
|
5170 | 5170 | " max_count=1,\n",
|
5171 |
| - " output_name='ny_tract_bus_stop_dist'+ str(datetime.now().microsecond))\n", |
| 5171 | + " output_name='ny_tract_bus_stop_dist'+ str(dt.now().microsecond))\n", |
5172 | 5172 | "tract_bustop_dist_lyr = tract_bustop_dist.layers[1]\n",
|
5173 |
| - "sdf_tract_bustop_dist_lyr = pd.DataFrame.spatial.from_layer(tract_bustop_dist_lyr)" |
| 5173 | + "sdf_tract_bustop_dist_lyr =tract_bustop_dist_lyr.query().sdf" |
5174 | 5174 | ]
|
5175 | 5175 | },
|
5176 | 5176 | {
|
|
5256 | 5256 | "source": [
|
5257 | 5257 | "# Final Bustop Distances in feet — Here in each row column \"busstop_dist\" returns the distance of the nearest bus stop \n",
|
5258 | 5258 | "# from that tract indicated by its geoids \n",
|
5259 |
| - "sdf_tract_bustop_dist_lyr_new = sdf_tract_bustop_dist_lyr[['From_geoid', 'Total_Miles']]\n", |
5260 |
| - "sdf_tract_bustop_dist_lyr_new['busstop_dist'] = round(sdf_tract_bustop_dist_lyr_new['Total_Miles'] * 5280)\n", |
| 5259 | + "sdf_tract_bustop_dist_lyr_new = sdf_tract_bustop_dist_lyr[['From_geoid', 'Total_Kilometers']]\n", |
| 5260 | + "sdf_tract_bustop_dist_lyr_new['busstop_dist'] = round(sdf_tract_bustop_dist_lyr_new['Total_Kilometers'] * 3280.84, 2)\n", |
5261 | 5261 | "sdf_tract_bustop_dist_lyr_new.sort_values('From_geoid').head()"
|
5262 | 5262 | ]
|
5263 | 5263 | },
|
|
5270 | 5270 | "# estimating number of bus stops per tract\n",
|
5271 | 5271 | "num_bustops_tracts = summarize_data.aggregate_points(point_layer=bus_stop_lyr,\n",
|
5272 | 5272 | " polygon_layer=nyc_tracts_layer,\n",
|
5273 |
| - " output_name='bustops_by_tracts'+ str(datetime.now().microsecond)) " |
| 5273 | + " output_name='bustops_by_tracts'+ str(dt.now().microsecond)) " |
5274 | 5274 | ]
|
5275 | 5275 | },
|
5276 | 5276 | {
|
|
5847 | 5847 | " cbd_lyr,\n",
|
5848 | 5848 | " measurement_type='StraightLine',\n",
|
5849 | 5849 | " max_count=1,\n",
|
5850 |
| - " output_name='ny_tract_cbd_dist'+ str(datetime.now().microsecond))\n", |
| 5850 | + " output_name='ny_tract_cbd_dist'+ str(dt.now().microsecond))\n", |
5851 | 5851 | "tract_cbd_dist_lyr = tract_cbd_dist.layers[1]\n",
|
5852 |
| - "sdf_tract_cbd_dist_lyr = pd.DataFrame.spatial.from_layer(tract_cbd_dist_lyr)\n", |
| 5852 | + "sdf_tract_cbd_dist_lyr = tract_cbd_dist_lyr.query().sdf\n", |
5853 | 5853 | "sdf_tract_cbd_dist_lyr.head()"
|
5854 | 5854 | ]
|
5855 | 5855 | },
|
|
5935 | 5935 | ],
|
5936 | 5936 | "source": [
|
5937 | 5937 | "# Final CBD distances in feet — Here in each row the column \"cbd_dst\" returns the distance of the CBD from respective tracts\n",
|
5938 |
| - "sdf_tract_cbd_dist_lyr_new = sdf_tract_cbd_dist_lyr[['From_geoid', 'Total_Miles']]\n", |
5939 |
| - "sdf_tract_cbd_dist_lyr_new['cbd_dist'] = round(sdf_tract_cbd_dist_lyr_new['Total_Miles'] * 5280, 2) \n", |
| 5938 | + "sdf_tract_cbd_dist_lyr_new = sdf_tract_cbd_dist_lyr[['From_geoid', 'Total_Kilometers']]\n", |
| 5939 | + "sdf_tract_cbd_dist_lyr_new['cbd_dist'] = round(sdf_tract_cbd_dist_lyr_new['Total_Kilometers'] * 3280.84, 2) \n", |
5940 | 5940 | "sdf_tract_cbd_dist_lyr_new.sort_values('From_geoid').head()"
|
5941 | 5941 | ]
|
5942 | 5942 | },
|
|
6200 | 6200 | " subwy_stn_lyr,\n",
|
6201 | 6201 | " measurement_type='StraightLine',\n",
|
6202 | 6202 | " max_count=1,\n",
|
6203 |
| - " output_name='ny_tract_subway_station_dist'+ str(datetime.now().microsecond))\n", |
| 6203 | + " output_name='ny_tract_subway_station_dist'+ str(dt.now().microsecond))\n", |
6204 | 6204 | "tract_subwy_stn_dist_lyr = tract_subwy_stn_dist.layers[1]\n",
|
6205 | 6205 | "sdf_tract_subwy_stn_dist_lyr = pd.DataFrame.spatial.from_layer(tract_subwy_stn_dist_lyr)\n",
|
6206 | 6206 | "sdf_tract_subwy_stn_dist_lyr.head()"
|
|
6289 | 6289 | "source": [
|
6290 | 6290 | "# Final Tract to NYC Subway Station distances in feet — Here in each row, column \"subwy_stn_dist\" returns the distance of\n",
|
6291 | 6291 | "# the nearest subway station from that tract\n",
|
6292 |
| - "sdf_tract_subwy_stn_dist_lyr_new = sdf_tract_subwy_stn_dist_lyr[['From_geoid', 'Total_Miles']]\n", |
6293 |
| - "sdf_tract_subwy_stn_dist_lyr_new['subwy_stn_dist'] = round(sdf_tract_subwy_stn_dist_lyr_new['Total_Miles'] * 5280, 2) \n", |
| 6292 | + "sdf_tract_subwy_stn_dist_lyr_new = sdf_tract_subwy_stn_dist_lyr[['From_geoid', 'Total_Kilometers']]\n", |
| 6293 | + "sdf_tract_subwy_stn_dist_lyr_new['subwy_stn_dist'] = round(sdf_tract_subwy_stn_dist_lyr_new['Total_Kilometers'] * 3280.84, 2) \n", |
6294 | 6294 | "sdf_tract_subwy_stn_dist_lyr_new.sort_values('From_geoid').head()"
|
6295 | 6295 | ]
|
6296 | 6296 | },
|
|
6547 | 6547 | " subwy_rt_lyr,\n",
|
6548 | 6548 | " measurement_type='StraightLine',\n",
|
6549 | 6549 | " max_count=1,\n",
|
6550 |
| - " output_name='ny_tract_subway_routes_dist'+ str(datetime.now().microsecond))\n", |
| 6550 | + " output_name='ny_tract_subway_routes_dist'+ str(dt.now().microsecond))\n", |
6551 | 6551 | "tract_subwy_rt_dist_lyr = tract_subwy_rt_dist.layers[1]\n",
|
6552 |
| - "sdf_tract_subwy_rt_dist_lyr = pd.DataFrame.spatial.from_layer(tract_subwy_rt_dist_lyr)\n", |
| 6552 | + "sdf_tract_subwy_rt_dist_lyr = tract_subwy_rt_dist_lyr.query().sdf\n", |
6553 | 6553 | "sdf_tract_subwy_rt_dist_lyr.head()"
|
6554 | 6554 | ]
|
6555 | 6555 | },
|
|
6636 | 6636 | "source": [
|
6637 | 6637 | "# Final Tract to NYCSubwayRoutes distances in feet — Here in each row, column \"subwy_rt_dist\" returns the distance of\n",
|
6638 | 6638 | "# the nearest subway route from that tract\n",
|
6639 |
| - "sdf_tract_subwy_rt_dist_lyr_new = sdf_tract_subwy_rt_dist_lyr[['From_geoid', 'Total_Miles']]\n", |
6640 |
| - "sdf_tract_subwy_rt_dist_lyr_new['subwy_rt_dist'] = round(sdf_tract_subwy_rt_dist_lyr_new['Total_Miles'] * 5280) \n", |
| 6639 | + "sdf_tract_subwy_rt_dist_lyr_new = sdf_tract_subwy_rt_dist_lyr[['From_geoid', 'Total_Kilometers']]\n", |
| 6640 | + "sdf_tract_subwy_rt_dist_lyr_new['subwy_rt_dist'] = round(sdf_tract_subwy_rt_dist_lyr_new['Total_Kilometers'] * 3280.84, 2) \n", |
6641 | 6641 | "sdf_tract_subwy_rt_dist_lyr_new.sort_values('From_geoid').head()"
|
6642 | 6642 | ]
|
6643 | 6643 | },
|
|
6869 | 6869 | " railroad_lyr,\n",
|
6870 | 6870 | " measurement_type='StraightLine',\n",
|
6871 | 6871 | " max_count=1,\n",
|
6872 |
| - " output_name='tract_railroad_dist'+ str(datetime.now().microsecond))\n", |
| 6872 | + " output_name='tract_railroad_dist'+ str(dt.now().microsecond))\n", |
6873 | 6873 | "tract_railroad_dist_lyr = tract_railroad_dist.layers[1]\n",
|
6874 | 6874 | "sdf_tract_railroad_dist_lyr = pd.DataFrame.spatial.from_layer(tract_railroad_dist_lyr)\n",
|
6875 | 6875 | "sdf_tract_railroad_dist_lyr.head()"
|
|
6958 | 6958 | "source": [
|
6959 | 6959 | "# Final Tract to NYCRailroad distances in feet — Here in each row, column \"railroad_dist\" returns the distance of\n",
|
6960 | 6960 | "# the nearest rail road route from that tract\n",
|
6961 |
| - "sdf_tract_railroad_dist_lyr_new = sdf_tract_railroad_dist_lyr[['From_geoid', 'Total_Miles']]\n", |
6962 |
| - "sdf_tract_railroad_dist_lyr_new['railroad_dist'] = round(sdf_tract_railroad_dist_lyr_new['Total_Miles'] * 5280, 2) \n", |
| 6961 | + "sdf_tract_railroad_dist_lyr_new = sdf_tract_railroad_dist_lyr[['From_geoid', 'Total_Kilometers']]\n", |
| 6962 | + "sdf_tract_railroad_dist_lyr_new['railroad_dist'] = round(sdf_tract_railroad_dist_lyr_new['Total_Kilometers'] * 3280.84, 2) \n", |
6963 | 6963 | "sdf_tract_railroad_dist_lyr_new.sort_values('From_geoid').head()"
|
6964 | 6964 | ]
|
6965 | 6965 | },
|
|
7259 | 7259 | " busi_distrs_lyr,\n",
|
7260 | 7260 | " measurement_type='StraightLine',\n",
|
7261 | 7261 | " max_count=1,\n",
|
7262 |
| - " output_name='tract_busi_distrs_dist'+ str(datetime.now().microsecond))\n", |
| 7262 | + " output_name='tract_busi_distrs_dist'+ str(dt.now().microsecond))\n", |
7263 | 7263 | "tract_busi_distrs_dist_lyr = tract_busi_distrs_dist.layers[1]\n",
|
7264 | 7264 | "sdf_tract_busi_distrs_dist_lyr = pd.DataFrame.spatial.from_layer(tract_busi_distrs_dist_lyr)\n",
|
7265 | 7265 | "sdf_tract_busi_distrs_dist_lyr.head()"
|
|
7347 | 7347 | ],
|
7348 | 7348 | "source": [
|
7349 | 7349 | "# Final Tract to NYC Businesss Districts distances in feet — Here in each row, column \"busi_distr_dist\" returns the distance of the CBD from respective tracts\n",
|
7350 |
| - "sdf_tract_busi_distrs_dist_lyr_new = sdf_tract_busi_distrs_dist_lyr[['From_geoid', 'Total_Miles']]\n", |
7351 |
| - "sdf_tract_busi_distrs_dist_lyr_new['busi_distr_dist'] = round(sdf_tract_busi_distrs_dist_lyr_new['Total_Miles'] * 5280, 2) \n", |
| 7350 | + "sdf_tract_busi_distrs_dist_lyr_new = sdf_tract_busi_distrs_dist_lyr[['From_geoid', 'Total_Kilometers']]\n", |
| 7351 | + "sdf_tract_busi_distrs_dist_lyr_new['busi_distr_dist'] = round(sdf_tract_busi_distrs_dist_lyr_new['Total_Kilometers'] * 3280.84, 2) \n", |
7352 | 7352 | "sdf_tract_busi_distrs_dist_lyr_new.sort_values('From_geoid').head()"
|
7353 | 7353 | ]
|
7354 | 7354 | },
|
|
8166 | 8166 | " 'ID',\n",
|
8167 | 8167 | " 'OBJECTID',\n",
|
8168 | 8168 | " 'Point_Count',\n",
|
8169 |
| - " 'SHAPE',\n", |
8170 |
| - " 'Shape__Area',\n", |
8171 |
| - " 'Shape__Length',\n", |
| 8169 | + " 'SHAPE', \n", |
8172 | 8170 | " 'aggregationMethod',\n",
|
8173 | 8171 | " 'aland',\n",
|
8174 | 8172 | " 'apportionmentConfidence',\n",
|
|
10439 | 10437 | "# plotting the actual observed vs predicted airbnb properties by tract\n",
|
10440 | 10438 | "plt.figure(figsize = [25,12])\n",
|
10441 | 10439 | "sns.set(style = 'whitegrid')\n",
|
10442 |
| - "sns.lineplot(data = y_test_df, markers=True, hue=\"logic\") \n", |
| 10440 | + "sns.lineplot(data = y_test_df, markers=True) \n", |
10443 | 10441 | "\n",
|
10444 | 10442 | "#label the plot\n",
|
10445 | 10443 | "plt.xlabel('Tract ID', fontsize=15)\n",
|
|
10519 | 10517 | "notebookRuntimeVersion": "4.0"
|
10520 | 10518 | },
|
10521 | 10519 | "kernelspec": {
|
10522 |
| - "display_name": "Python 3", |
| 10520 | + "display_name": "pro28_DL18FebA", |
10523 | 10521 | "language": "python",
|
10524 |
| - "name": "python3" |
| 10522 | + "name": "pro28_dl18feba" |
10525 | 10523 | },
|
10526 | 10524 | "language_info": {
|
10527 | 10525 | "codemirror_mode": {
|
|
10533 | 10531 | "name": "python",
|
10534 | 10532 | "nbconvert_exporter": "python",
|
10535 | 10533 | "pygments_lexer": "ipython3",
|
10536 |
| - "version": "3.6.8" |
| 10534 | + "version": "3.7.9" |
10537 | 10535 | }
|
10538 | 10536 | },
|
10539 | 10537 | "nbformat": 4,
|
|
0 commit comments