{ "cells": [ { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "import geohash\n", "from kml_template import header, footer, box_template, red_template, orange_template, yellow_template, green_template\n", "import geohashlite\n", "import json\n", "\n", "airof18 = pd.read_csv('./Air Tube/data_bg_2018.csv')\n", "airof17 = pd.read_csv('./Air Tube/data_bg_2017.csv')\n", "\n", "air = airof18.append(airof17, ignore_index=True)\n", "\n", "airdict = dict(tuple(air.groupby('geohash')))\n", "\n", "temperature = {}\n", "humidity = {}\n", "pressure = {}\n", "p1 = {}\n", "p2 = {}\n", "\n", "prev = ''\n", "\n", "for i,j in airdict.items():\n", " j.drop('geohash', axis=1, inplace=True)\n", " #removing geohash column, because it'd be redundant to keep it\n", " j['temperature'].replace(to_replace=0, method='ffill')\n", " j['humidity'].replace(to_replace=0, method='ffill')\n", " j['pressure'].replace(to_replace=0, method='ffill')\n", " #using ffill after all the geohashes have been separated so that values of two geohashes don't get forward filled\n", " if i != prev :\n", " temperature[i] = j['temperature'].mean()\n", " humidity[i] = j['humidity'].mean()\n", " pressure[i] = j['pressure'].mean()\n", " p1[i] = j['P1'].mean()\n", " p2[i] = j['P2'].mean()\n", " prev = i\n", " #to make sure the mean of all the columns gets calculated once and not 'the number of elements present in the column' times\n", " #because that would be very redunant to calculate mean that many number of times. \n" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [], "source": [ "import folium\n", "import folium.plugins as plugins\n", "from folium.plugins import HeatMap\n", "\n", "def display(dictionary):\n", " temp = []\n", " for i,j in dictionary.items():\n", " try:\n", " cor = geohash.decode_exactly(i)\n", " lat = cor[0]\n", " lon = cor[1]\n", " temp.append([lat,lon,j])\n", " except:\n", " None\n", " m = folium.Map([42., 26.], tiles='stamentoner', zoom_start=7)\n", "\n", " HeatMap(temp).add_to(m)\n", "\n", " return m" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [ { "data": { "text/html": [ "