{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# WeatherPy\n", "----\n", "\n", "#### Note\n", "* Instructions have been included for each segment. You do not have to follow them exactly, but they are included to help you think through the steps." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Observable Trends and Insights\n", " #### 1. The findings of these analysis showed that there is a higher temperature for cities that found near to the equator (Latitude 0), however, when we go farther from the equator towards the north the temperature decreases highly. However, when we go to the south the temperature decreases but it is much lower comparing to the north. The regression analysis and plot also showed that there is a strong negative correlation between temperature, and latitude in the northern hemisphere however, the correlation between temperature and latitude in the south Hemisphere is negative but very week to conclude. \n", " \n", " \n", " #### 2. The findings from the data, plots, and the regression line in the case of testing if there is a relation between humidity and cloudiness of cities nearer or farther to the equator (latitude 0) doesn't show any significant results. The correlation between humidity and latitude for both northern and southern hemisphere cities is very week, negative correlation, and the result for cloudiness and latitude also very week and negative. Therefore, We can infer that humidity can be fairly distributed in both northern and southern hemisphere cities regardless of their distance from the equator.\n", " \n", " #### 3. The finding from the analysis of the relationship between wind speed (mph), and latitude showed that the lower wind speed when the cities closer to the equater (latitude 0), and somehow the wind speed increase for the cities farther from the equater. The regression analysis also showed that there is a very week, posetive correlation between Wind Speed (mph (%) and Latitude in the Northern Hemisphere cities.\n", " " ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "scrolled": true }, "outputs": [], "source": [ "# Dependencies and Setup\n", "import matplotlib.pyplot as plt\n", "import pandas as pd\n", "import numpy as np\n", "import requests\n", "import time\n", "from datetime import datetime\n", "from scipy.stats import linregress\n", "import scipy.stats as st\n", "\n", "# Import API key\n", "from api_keys import weather_api_key\n", "\n", "# Incorporated citipy to determine city based on latitude and longitude\n", "from citipy import citipy\n", "\n", "# Output File (CSV)\n", "output_data_file = \"output_data/cities.csv\"\n", "\n", "# Range of latitudes and longitudes\n", "lat_range = (-90, 90)\n", "lng_range = (-180, 180)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Generate Cities List" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "639" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# List for holding lat_lngs and cities\n", "lat_lngs = []\n", "cities = []\n", "\n", "# Create a set of random lat and lng combinations\n", "lats = np.random.uniform(low=-90.000, high=90.000, size=1500)\n", "lngs = np.random.uniform(low=-180.000, high=180.000, size=1500)\n", "lat_lngs = zip(lats, lngs)\n", "\n", "# Identify nearest city for each lat, lng combination\n", "for lat_lng in lat_lngs:\n", " city = citipy.nearest_city(lat_lng[0], lat_lng[1]).city_name\n", " \n", " # If the city is unique, then add it to a our cities list\n", " if city not in cities:\n", " cities.append(city)\n", "\n", "# Print the city count to confirm sufficient count\n", "len(cities)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Perform API Calls\n", "* Perform a weather check on each city using a series of successive API calls.\n", "* Include a print log of each city as it'sbeing processed (with the city number and city name).\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# Url and units\n", "url = \"http://api.openweathermap.org/data/2.5/weather?\"\n", "units = \"imperial\"\n", "\n", "# Build query URL\n", "query_url = f\"{url}appid={weather_api_key}&units={units}&q=\"\n", " " ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Beginning Data Retrieval\n", "--------------------------------------------\n", "Processing Record 1 of Set 1 | severo-kurilsk\n", "Processing Record 2 of Set 1 | ust-kamchatsk\n", "City not found. Skipping...\n", "Processing Record 3 of Set 1 | vaini\n", "Processing Record 4 of Set 1 | cidreira\n", "Processing Record 5 of Set 1 | taolanaro\n", "City not found. Skipping...\n", "Processing Record 6 of Set 1 | kalmar\n", "Processing Record 7 of Set 1 | merauke\n", "Processing Record 8 of Set 1 | barrow\n", "Processing Record 9 of Set 1 | mahebourg\n", "Processing Record 10 of Set 1 | east london\n", "Processing Record 11 of Set 1 | albany\n", "Processing Record 12 of Set 1 | codrington\n", "Processing Record 13 of Set 1 | pangai\n", "Processing Record 14 of Set 1 | yarim\n", "Processing Record 15 of Set 1 | trelew\n", "Processing Record 16 of Set 1 | dingle\n", "Processing Record 17 of Set 1 | jacmel\n", "Processing Record 18 of Set 1 | butaritari\n", "Processing Record 19 of Set 1 | punta arenas\n", "Processing Record 20 of Set 1 | yellowknife\n", "Processing Record 21 of Set 1 | port keats\n", "Processing Record 22 of Set 1 | thinadhoo\n", "Processing Record 23 of Set 1 | masuguru\n", "Processing Record 24 of Set 1 | guerrero negro\n", "Processing Record 25 of Set 1 | shingu\n", "Processing Record 26 of Set 1 | port elizabeth\n", "Processing Record 27 of Set 1 | porto velho\n", "Processing Record 28 of Set 1 | broome\n", "Processing Record 29 of Set 1 | castro\n", "Processing Record 30 of Set 1 | katherine\n", "Processing Record 31 of Set 1 | umba\n", "Processing Record 32 of Set 1 | kahului\n", "Processing Record 33 of Set 1 | kodiak\n", "Processing Record 34 of Set 1 | goderich\n", "Processing Record 35 of Set 1 | atar\n", "Processing Record 36 of Set 1 | belushya guba\n", "City not found. Skipping...\n", "Processing Record 37 of Set 1 | port alfred\n", "Processing Record 38 of Set 1 | santa eulalia del rio\n", "City not found. Skipping...\n", "Processing Record 39 of Set 1 | avarua\n", "Processing Record 40 of Set 1 | rikitea\n", "Processing Record 41 of Set 1 | hithadhoo\n", "Processing Record 42 of Set 1 | bredasdorp\n", "Processing Record 43 of Set 1 | klaksvik\n", "Processing Record 44 of Set 1 | arraial do cabo\n", "Processing Record 45 of Set 1 | ambodifototra\n", "City not found. Skipping...\n", "Processing Record 46 of Set 1 | tasiilaq\n", "Processing Record 47 of Set 1 | soltvadkert\n", "Processing Record 48 of Set 1 | mar del plata\n", "Processing Record 49 of Set 1 | kapaa\n", "Processing Record 50 of Set 1 | karkaralinsk\n", "City not found. Skipping...\n", "Processing Record 1 of Set 2 | busselton\n", "Processing Record 2 of Set 2 | hobart\n", "Processing Record 3 of Set 2 | yaguachi\n", "Processing Record 4 of Set 2 | aiquile\n", "Processing Record 5 of Set 2 | mamallapuram\n", "Processing Record 6 of Set 2 | tuktoyaktuk\n", "Processing Record 7 of Set 2 | los llanos de aridane\n", "Processing Record 8 of Set 2 | ibra\n", "Processing Record 9 of Set 2 | ugoofaaru\n", "Processing Record 10 of Set 2 | nikolskoye\n", "Processing Record 11 of Set 2 | nanortalik\n", "Processing Record 12 of Set 2 | portland\n", "Processing Record 13 of Set 2 | lata\n", "Processing Record 14 of Set 2 | kaitangata\n", "Processing Record 15 of Set 2 | kattivakkam\n", "Processing Record 16 of Set 2 | miraflores\n", "Processing Record 17 of Set 2 | ponta do sol\n", "Processing Record 18 of Set 2 | liniere\n", "City not found. Skipping...\n", "Processing Record 19 of Set 2 | simao dias\n", "Processing Record 20 of Set 2 | saskylakh\n", "Processing Record 21 of Set 2 | vyara\n", "Processing Record 22 of Set 2 | ksenyevka\n", "City not found. Skipping...\n", "Processing Record 23 of Set 2 | karratha\n", "Processing Record 24 of Set 2 | mataura\n", "Processing Record 25 of Set 2 | thompson\n", "Processing Record 26 of Set 2 | havoysund\n", "Processing Record 27 of Set 2 | bueu\n", "Processing Record 28 of Set 2 | palana\n", "Processing Record 29 of Set 2 | iqaluit\n", "Processing Record 30 of Set 2 | saint-pierre\n", "Processing Record 31 of Set 2 | henties bay\n", "Processing Record 32 of Set 2 | miles city\n", "Processing Record 33 of Set 2 | aksay\n", "Processing Record 34 of Set 2 | toliary\n", "City not found. Skipping...\n", "Processing Record 35 of Set 2 | christchurch\n", "Processing Record 36 of Set 2 | tabiauea\n", "City not found. Skipping...\n", "Processing Record 37 of Set 2 | atuona\n", "Processing Record 38 of Set 2 | uvalde\n", "Processing Record 39 of Set 2 | shahr-e babak\n", "Processing Record 40 of Set 2 | grand gaube\n", "Processing Record 41 of Set 2 | khatanga\n", "Processing Record 42 of Set 2 | bonavista\n", "Processing Record 43 of Set 2 | ayios serafim\n", "Processing Record 44 of Set 2 | jamestown\n", "Processing Record 45 of Set 2 | sumenep\n", "Processing Record 46 of Set 2 | melfi\n", "Processing Record 47 of Set 2 | sioux lookout\n", "Processing Record 48 of Set 2 | mitsamiouli\n", "Processing Record 49 of Set 2 | inongo\n", "Processing Record 50 of Set 2 | wonthaggi\n", "Processing Record 1 of Set 3 | port moresby\n", "Processing Record 2 of Set 3 | qaanaaq\n", "Processing Record 3 of Set 3 | chuy\n", "Processing Record 4 of Set 3 | gorkovskoye\n", "City not found. Skipping...\n", "Processing Record 5 of Set 3 | provideniya\n", "Processing Record 6 of Set 3 | formoso do araguaia\n", "City not found. Skipping...\n", "Processing Record 7 of Set 3 | hangu\n", "Processing Record 8 of Set 3 | gardan diwal\n", "City not found. Skipping...\n", "Processing Record 9 of Set 3 | chadiza\n", "Processing Record 10 of Set 3 | camabatela\n", "Processing Record 11 of Set 3 | vila franca do campo\n", "Processing Record 12 of Set 3 | bluff\n", "Processing Record 13 of Set 3 | payakumbuh\n", "Processing Record 14 of Set 3 | tura\n", "Processing Record 15 of Set 3 | hovd\n", "Processing Record 16 of Set 3 | ushuaia\n", "Processing Record 17 of Set 3 | bengkulu\n", "Processing Record 18 of Set 3 | pokhara\n", "Processing Record 19 of Set 3 | zhuozhou\n", "City not found. Skipping...\n", "Processing Record 20 of Set 3 | andra\n", "Processing Record 21 of Set 3 | camopi\n", "Processing Record 22 of Set 3 | port blair\n", "Processing Record 23 of Set 3 | skalat\n", "Processing Record 24 of Set 3 | vaasa\n", "Processing Record 25 of Set 3 | sorong\n", "Processing Record 26 of Set 3 | tiksi\n", "Processing Record 27 of Set 3 | fortuna\n", "Processing Record 28 of Set 3 | vostok\n", "Processing Record 29 of Set 3 | inverell\n", "Processing Record 30 of Set 3 | tecpatan\n", "Processing Record 31 of Set 3 | carnarvon\n", "Processing Record 32 of Set 3 | marcona\n", "City not found. Skipping...\n", "Processing Record 33 of Set 3 | lorengau\n", "Processing Record 34 of Set 3 | vardo\n", "Processing Record 35 of Set 3 | amahai\n", "Processing Record 36 of Set 3 | ostrovnoy\n", "Processing Record 37 of Set 3 | sabha\n", "Processing Record 38 of Set 3 | cabo san lucas\n", "Processing Record 39 of Set 3 | provadija\n", "City not found. Skipping...\n", "Processing Record 40 of Set 3 | cayenne\n", "Processing Record 41 of Set 3 | bethel\n", "Processing Record 42 of Set 3 | norman wells\n", "Processing Record 43 of Set 3 | samalaeulu\n", "City not found. Skipping...\n", "Processing Record 44 of Set 3 | mehamn\n", "Processing Record 45 of Set 3 | saint-philippe\n", "Processing Record 46 of Set 3 | xalpatlahuac\n", "Processing Record 47 of Set 3 | nizhneyansk\n", "City not found. Skipping...\n", "Processing Record 48 of Set 3 | coihaique\n", "Processing Record 49 of Set 3 | catamarca\n", "Processing Record 50 of Set 3 | sitka\n", "Processing Record 1 of Set 4 | new norfolk\n", "Processing Record 2 of Set 4 | sanmenxia\n", "Processing Record 3 of Set 4 | acapulco\n", "Processing Record 4 of Set 4 | saleaula\n", "City not found. Skipping...\n", "Processing Record 5 of Set 4 | illoqqortoormiut\n", "City not found. Skipping...\n", "Processing Record 6 of Set 4 | cape town\n", "Processing Record 7 of Set 4 | camocim\n", "Processing Record 8 of Set 4 | flinders\n", "Processing Record 9 of Set 4 | novikovo\n", "Processing Record 10 of Set 4 | pisek\n", "Processing Record 11 of Set 4 | aswan\n", "Processing Record 12 of Set 4 | iskateley\n", "Processing Record 13 of Set 4 | amderma\n", "City not found. Skipping...\n", "Processing Record 14 of Set 4 | ahipara\n", "Processing Record 15 of Set 4 | puerto ayora\n", "Processing Record 16 of Set 4 | navalcarnero\n", "Processing Record 17 of Set 4 | lac du bonnet\n", "Processing Record 18 of Set 4 | hermanus\n", "Processing Record 19 of Set 4 | vaitupu\n", "City not found. Skipping...\n", "Processing Record 20 of Set 4 | qurayyat\n", "Processing Record 21 of Set 4 | inirida\n", "Processing Record 22 of Set 4 | saint-georges\n", "Processing Record 23 of Set 4 | georgetown\n", "Processing Record 24 of Set 4 | bambous virieux\n", "Processing Record 25 of Set 4 | pevek\n", "Processing Record 26 of Set 4 | luderitz\n", "Processing Record 27 of Set 4 | kiparissia\n", "City not found. Skipping...\n", "Processing Record 28 of Set 4 | sidi ali\n", "Processing Record 29 of Set 4 | leningradskiy\n", "Processing Record 30 of Set 4 | kargasok\n", "Processing Record 31 of Set 4 | upernavik\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Processing Record 32 of Set 4 | attawapiskat\n", "City not found. Skipping...\n", "Processing Record 33 of Set 4 | dikson\n", "Processing Record 34 of Set 4 | dunedin\n", "Processing Record 35 of Set 4 | airai\n", "Processing Record 36 of Set 4 | castlegar\n", "Processing Record 37 of Set 4 | pangnirtung\n", "Processing Record 38 of Set 4 | port-gentil\n", "Processing Record 39 of Set 4 | itaituba\n", "Processing Record 40 of Set 4 | kruisfontein\n", "Processing Record 41 of Set 4 | yeletskiy\n", "City not found. Skipping...\n", "Processing Record 42 of Set 4 | richards bay\n", "Processing Record 43 of Set 4 | alyangula\n", "Processing Record 44 of Set 4 | qandala\n", "Processing Record 45 of Set 4 | zhigansk\n", "Processing Record 46 of Set 4 | castelo do piaui\n", "Processing Record 47 of Set 4 | torbay\n", "Processing Record 48 of Set 4 | aklavik\n", "Processing Record 49 of Set 4 | durant\n", "Processing Record 50 of Set 4 | mount isa\n", "Processing Record 1 of Set 5 | esperance\n", "Processing Record 2 of Set 5 | rawannawi\n", "City not found. Skipping...\n", "Processing Record 3 of Set 5 | biak\n", "Processing Record 4 of Set 5 | beloha\n", "Processing Record 5 of Set 5 | oussouye\n", "Processing Record 6 of Set 5 | staryy nadym\n", "Processing Record 7 of Set 5 | chiang klang\n", "Processing Record 8 of Set 5 | gigmoto\n", "Processing Record 9 of Set 5 | byron bay\n", "Processing Record 10 of Set 5 | magura ilvei\n", "Processing Record 11 of Set 5 | nantucket\n", "Processing Record 12 of Set 5 | lebu\n", "Processing Record 13 of Set 5 | saint george\n", "Processing Record 14 of Set 5 | alofi\n", "Processing Record 15 of Set 5 | santiago del estero\n", "Processing Record 16 of Set 5 | nueva germania\n", "Processing Record 17 of Set 5 | hilo\n", "Processing Record 18 of Set 5 | berlevag\n", "Processing Record 19 of Set 5 | buta\n", "Processing Record 20 of Set 5 | plettenberg bay\n", "Processing Record 21 of Set 5 | umzimvubu\n", "City not found. Skipping...\n", "Processing Record 22 of Set 5 | ashiya\n", "Processing Record 23 of Set 5 | rexburg\n", "Processing Record 24 of Set 5 | necochea\n", "Processing Record 25 of Set 5 | taoudenni\n", "Processing Record 26 of Set 5 | havre-saint-pierre\n", "Processing Record 27 of Set 5 | samusu\n", "City not found. Skipping...\n", "Processing Record 28 of Set 5 | baruun-urt\n", "Processing Record 29 of Set 5 | yar-sale\n", "Processing Record 30 of Set 5 | port augusta\n", "Processing Record 31 of Set 5 | chumikan\n", "Processing Record 32 of Set 5 | okhotsk\n", "Processing Record 33 of Set 5 | saldanha\n", "Processing Record 34 of Set 5 | pisco\n", "Processing Record 35 of Set 5 | sarkand\n", "Processing Record 36 of Set 5 | idritsa\n", "Processing Record 37 of Set 5 | kalmunai\n", "Processing Record 38 of Set 5 | tutoia\n", "Processing Record 39 of Set 5 | hami\n", "Processing Record 40 of Set 5 | grand-lahou\n", "Processing Record 41 of Set 5 | asyut\n", "Processing Record 42 of Set 5 | abu samrah\n", "Processing Record 43 of Set 5 | axim\n", "Processing Record 44 of Set 5 | shu\n", "Processing Record 45 of Set 5 | brasileia\n", "Processing Record 46 of Set 5 | mayumba\n", "Processing Record 47 of Set 5 | alice springs\n", "Processing Record 48 of Set 5 | sao filipe\n", "Processing Record 49 of Set 5 | namtsy\n", "Processing Record 50 of Set 5 | villarrica\n", "Processing Record 1 of Set 6 | anadyr\n", "Processing Record 2 of Set 6 | saint anthony\n", "Processing Record 3 of Set 6 | longyearbyen\n", "Processing Record 4 of Set 6 | guilin\n", "Processing Record 5 of Set 6 | ribeira brava\n", "Processing Record 6 of Set 6 | tromso\n", "Processing Record 7 of Set 6 | neiafu\n", "Processing Record 8 of Set 6 | perelyub\n", "Processing Record 9 of Set 6 | hit\n", "Processing Record 10 of Set 6 | faanui\n", "Processing Record 11 of Set 6 | yulara\n", "Processing Record 12 of Set 6 | aykhal\n", "Processing Record 13 of Set 6 | rafraf\n", "Processing Record 14 of Set 6 | nyimba\n", "Processing Record 15 of Set 6 | aripuana\n", "Processing Record 16 of Set 6 | seymchan\n", "Processing Record 17 of Set 6 | mawlaik\n", "Processing Record 18 of Set 6 | abu kamal\n", "Processing Record 19 of Set 6 | makaha\n", "Processing Record 20 of Set 6 | tubinskiy\n", "Processing Record 21 of Set 6 | chokurdakh\n", "Processing Record 22 of Set 6 | alto araguaia\n", "Processing Record 23 of Set 6 | bayji\n", "Processing Record 24 of Set 6 | te anau\n", "Processing Record 25 of Set 6 | nanded\n", "City not found. Skipping...\n", "Processing Record 26 of Set 6 | altamont\n", "Processing Record 27 of Set 6 | chapais\n", "Processing Record 28 of Set 6 | sentyabrskiy\n", "City not found. Skipping...\n", "Processing Record 29 of Set 6 | hamina\n", "Processing Record 30 of Set 6 | oksfjord\n", "Processing Record 31 of Set 6 | sukabumi\n", "Processing Record 32 of Set 6 | namibe\n", "Processing Record 33 of Set 6 | ustek\n", "Processing Record 34 of Set 6 | mys shmidta\n", "City not found. Skipping...\n", "Processing Record 35 of Set 6 | plouzane\n", "Processing Record 36 of Set 6 | tsihombe\n", "City not found. Skipping...\n", "Processing Record 37 of Set 6 | labuhan\n", "Processing Record 38 of Set 6 | muros\n", "Processing Record 39 of Set 6 | olinda\n", "Processing Record 40 of Set 6 | kendari\n", "Processing Record 41 of Set 6 | kropotkin\n", "Processing Record 42 of Set 6 | souillac\n", "Processing Record 43 of Set 6 | karagay\n", "Processing Record 44 of Set 6 | chatrapur\n", "Processing Record 45 of Set 6 | ceres\n", "Processing Record 46 of Set 6 | rodrigues alves\n", "Processing Record 47 of Set 6 | imeni poliny osipenko\n", "Processing Record 48 of Set 6 | paita\n", "Processing Record 49 of Set 6 | chilca\n", "Processing Record 50 of Set 6 | santa cruz de la palma\n", "Processing Record 1 of Set 7 | sangar\n", "Processing Record 2 of Set 7 | stornoway\n", "Processing Record 3 of Set 7 | baglung\n", "Processing Record 4 of Set 7 | narsaq\n", "Processing Record 5 of Set 7 | marzuq\n", "Processing Record 6 of Set 7 | sambava\n", "Processing Record 7 of Set 7 | kupang\n", "Processing Record 8 of Set 7 | camacupa\n", "Processing Record 9 of Set 7 | tiradentes\n", "Processing Record 10 of Set 7 | tilichiki\n", "Processing Record 11 of Set 7 | batagay-alyta\n", "Processing Record 12 of Set 7 | viligili\n", "City not found. Skipping...\n", "Processing Record 13 of Set 7 | tuatapere\n", "Processing Record 14 of Set 7 | samarai\n", "Processing Record 15 of Set 7 | burica\n", "City not found. Skipping...\n", "Processing Record 16 of Set 7 | vao\n", "Processing Record 17 of Set 7 | trinidad\n", "Processing Record 18 of Set 7 | amboasary\n", "Processing Record 19 of Set 7 | pitimbu\n", "Processing Record 20 of Set 7 | ancud\n", "Processing Record 21 of Set 7 | huarmey\n", "Processing Record 22 of Set 7 | derzhavinsk\n", "Processing Record 23 of Set 7 | warqla\n", "City not found. Skipping...\n", "Processing Record 24 of Set 7 | tafalla\n", "Processing Record 25 of Set 7 | hillsborough\n", "Processing Record 26 of Set 7 | san patricio\n", "Processing Record 27 of Set 7 | isangel\n", "Processing Record 28 of Set 7 | calama\n", "Processing Record 29 of Set 7 | bonthe\n", "Processing Record 30 of Set 7 | caravelas\n", "Processing Record 31 of Set 7 | san juan\n", "Processing Record 32 of Set 7 | constitucion\n", "Processing Record 33 of Set 7 | balaipungut\n", "Processing Record 34 of Set 7 | kalashnikovo\n", "Processing Record 35 of Set 7 | marsh harbour\n", "Processing Record 36 of Set 7 | bacuit\n", "City not found. Skipping...\n", "Processing Record 37 of Set 7 | treinta y tres\n", "Processing Record 38 of Set 7 | izhma\n", "Processing Record 39 of Set 7 | barentsburg\n", "City not found. Skipping...\n", "Processing Record 40 of Set 7 | buchanan\n", "Processing Record 41 of Set 7 | mizque\n", "Processing Record 42 of Set 7 | ondangwa\n", "Processing Record 43 of Set 7 | san jeronimo\n", "Processing Record 44 of Set 7 | akureyri\n", "Processing Record 45 of Set 7 | qasigiannguit\n", "Processing Record 46 of Set 7 | iracoubo\n", "Processing Record 47 of Set 7 | sicuani\n", "Processing Record 48 of Set 7 | asau\n", "Processing Record 49 of Set 7 | uruzgan\n", "Processing Record 50 of Set 7 | hasaki\n", "Processing Record 1 of Set 8 | buraydah\n", "Processing Record 2 of Set 8 | roald\n", "Processing Record 3 of Set 8 | sal rei\n", "Processing Record 4 of Set 8 | krasyliv\n", "Processing Record 5 of Set 8 | cockburn town\n", "Processing Record 6 of Set 8 | altus\n", "Processing Record 7 of Set 8 | fairbanks\n", "Processing Record 8 of Set 8 | springdale\n", "Processing Record 9 of Set 8 | moree\n", "Processing Record 10 of Set 8 | clyde river\n", "Processing Record 11 of Set 8 | san quintin\n", "Processing Record 12 of Set 8 | ribeira grande\n", "Processing Record 13 of Set 8 | husavik\n", "Processing Record 14 of Set 8 | tautira\n", "Processing Record 15 of Set 8 | lubu\n", "Processing Record 16 of Set 8 | bakchar\n", "Processing Record 17 of Set 8 | cherskiy\n", "Processing Record 18 of Set 8 | novobirilyussy\n", "Processing Record 19 of Set 8 | grand river south east\n", "City not found. Skipping...\n", "Processing Record 20 of Set 8 | avera\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Processing Record 21 of Set 8 | asamankese\n", "Processing Record 22 of Set 8 | westport\n", "Processing Record 23 of Set 8 | belaya gora\n", "Processing Record 24 of Set 8 | meyungs\n", "City not found. Skipping...\n", "Processing Record 25 of Set 8 | mount gambier\n", "Processing Record 26 of Set 8 | rio grande\n", "Processing Record 27 of Set 8 | zhuanghe\n", "Processing Record 28 of Set 8 | suzhou\n", "Processing Record 29 of Set 8 | doha\n", "Processing Record 30 of Set 8 | wagar\n", "Processing Record 31 of Set 8 | malanje\n", "Processing Record 32 of Set 8 | nizwa\n", "Processing Record 33 of Set 8 | bereda\n", "Processing Record 34 of Set 8 | fort pierce\n", "Processing Record 35 of Set 8 | caxias\n", "Processing Record 36 of Set 8 | gujar khan\n", "Processing Record 37 of Set 8 | mareeba\n", "Processing Record 38 of Set 8 | itarema\n", "Processing Record 39 of Set 8 | tumannyy\n", "City not found. Skipping...\n", "Processing Record 40 of Set 8 | grindavik\n", "Processing Record 41 of Set 8 | meulaboh\n", "Processing Record 42 of Set 8 | northam\n", "Processing Record 43 of Set 8 | fukue\n", "Processing Record 44 of Set 8 | pangkalanbuun\n", "Processing Record 45 of Set 8 | agadez\n", "Processing Record 46 of Set 8 | jamiltepec\n", "Processing Record 47 of Set 8 | gijon\n", "Processing Record 48 of Set 8 | victoria\n", "Processing Record 49 of Set 8 | bogorodskoye\n", "Processing Record 50 of Set 8 | along\n", "Processing Record 1 of Set 9 | jijiga\n", "Processing Record 2 of Set 9 | ust-maya\n", "Processing Record 3 of Set 9 | jerome\n", "Processing Record 4 of Set 9 | santa flavia\n", "Processing Record 5 of Set 9 | qaqortoq\n", "Processing Record 6 of Set 9 | nouakchott\n", "Processing Record 7 of Set 9 | challans\n", "Processing Record 8 of Set 9 | puerto el triunfo\n", "Processing Record 9 of Set 9 | ucluelet\n", "Processing Record 10 of Set 9 | dunmore east\n", "Processing Record 11 of Set 9 | ahuimanu\n", "Processing Record 12 of Set 9 | jiayuguan\n", "Processing Record 13 of Set 9 | valparaiso\n", "Processing Record 14 of Set 9 | hanchuan\n", "Processing Record 15 of Set 9 | olafsvik\n", "Processing Record 16 of Set 9 | verkhoyansk\n", "Processing Record 17 of Set 9 | tambilil\n", "Processing Record 18 of Set 9 | hofn\n", "Processing Record 19 of Set 9 | haines junction\n", "Processing Record 20 of Set 9 | ruatoria\n", "City not found. Skipping...\n", "Processing Record 21 of Set 9 | omaruru\n", "Processing Record 22 of Set 9 | san carlos de bariloche\n", "Processing Record 23 of Set 9 | okha\n", "Processing Record 24 of Set 9 | sechura\n", "Processing Record 25 of Set 9 | yegorlykskaya\n", "Processing Record 26 of Set 9 | namatanai\n", "Processing Record 27 of Set 9 | shar\n", "Processing Record 28 of Set 9 | juneau\n", "Processing Record 29 of Set 9 | phu ly\n", "Processing Record 30 of Set 9 | halifax\n", "Processing Record 31 of Set 9 | palmer\n", "Processing Record 32 of Set 9 | hailun\n", "Processing Record 33 of Set 9 | nome\n", "Processing Record 34 of Set 9 | altay\n", "Processing Record 35 of Set 9 | katsuura\n", "Processing Record 36 of Set 9 | buala\n", "Processing Record 37 of Set 9 | osterhofen\n", "Processing Record 38 of Set 9 | canandaigua\n", "Processing Record 39 of Set 9 | hakkari\n", "Processing Record 40 of Set 9 | mandalgovi\n", "Processing Record 41 of Set 9 | phan thiet\n", "Processing Record 42 of Set 9 | wamba\n", "Processing Record 43 of Set 9 | tawkar\n", "City not found. Skipping...\n", "Processing Record 44 of Set 9 | payson\n", "Processing Record 45 of Set 9 | sur\n", "Processing Record 46 of Set 9 | birjand\n", "Processing Record 47 of Set 9 | nuuk\n", "Processing Record 48 of Set 9 | bure\n", "Processing Record 49 of Set 9 | george\n", "Processing Record 50 of Set 9 | puerto colombia\n", "Processing Record 1 of Set 10 | mrirt\n", "City not found. Skipping...\n", "Processing Record 2 of Set 10 | soma\n", "Processing Record 3 of Set 10 | sept-iles\n", "Processing Record 4 of Set 10 | lensk\n", "Processing Record 5 of Set 10 | anshun\n", "Processing Record 6 of Set 10 | sampit\n", "Processing Record 7 of Set 10 | sinop\n", "Processing Record 8 of Set 10 | aksu\n", "Processing Record 9 of Set 10 | ayan\n", "Processing Record 10 of Set 10 | korla\n", "Processing Record 11 of Set 10 | dukat\n", "Processing Record 12 of Set 10 | torit\n", "Processing Record 13 of Set 10 | luau\n", "Processing Record 14 of Set 10 | conakry\n", "Processing Record 15 of Set 10 | krasnoselkup\n", "Processing Record 16 of Set 10 | lompoc\n", "Processing Record 17 of Set 10 | redlands\n", "Processing Record 18 of Set 10 | jacareacanga\n", "Processing Record 19 of Set 10 | pandan\n", "Processing Record 20 of Set 10 | bojnurd\n", "Processing Record 21 of Set 10 | chagda\n", "City not found. Skipping...\n", "Processing Record 22 of Set 10 | caranavi\n", "Processing Record 23 of Set 10 | sao joao da barra\n", "Processing Record 24 of Set 10 | honiara\n", "Processing Record 25 of Set 10 | todos santos\n", "Processing Record 26 of Set 10 | tyler\n", "Processing Record 27 of Set 10 | palabuhanratu\n", "City not found. Skipping...\n", "Processing Record 28 of Set 10 | muroto\n", "Processing Record 29 of Set 10 | pospelikha\n", "Processing Record 30 of Set 10 | erzin\n", "Processing Record 31 of Set 10 | kloulklubed\n", "Processing Record 32 of Set 10 | victoria point\n", "Processing Record 33 of Set 10 | hambantota\n", "Processing Record 34 of Set 10 | paraiso\n", "Processing Record 35 of Set 10 | syracuse\n", "Processing Record 36 of Set 10 | hirara\n", "Processing Record 37 of Set 10 | malwan\n", "City not found. Skipping...\n", "Processing Record 38 of Set 10 | pochutla\n", "Processing Record 39 of Set 10 | port hardy\n", "Processing Record 40 of Set 10 | noumea\n", "Processing Record 41 of Set 10 | killybegs\n", "Processing Record 42 of Set 10 | simao\n", "Processing Record 43 of Set 10 | lloydminster\n", "Processing Record 44 of Set 10 | mogok\n", "Processing Record 45 of Set 10 | totma\n", "Processing Record 46 of Set 10 | kibala\n", "Processing Record 47 of Set 10 | chifeng\n", "Processing Record 48 of Set 10 | talnakh\n", "Processing Record 49 of Set 10 | naze\n", "Processing Record 50 of Set 10 | demyansk\n", "Processing Record 1 of Set 11 | doka\n", "Processing Record 2 of Set 11 | janovice nad uhlavou\n", "Processing Record 3 of Set 11 | rundu\n", "Processing Record 4 of Set 11 | codajas\n", "Processing Record 5 of Set 11 | bam\n", "Processing Record 6 of Set 11 | karaul\n", "City not found. Skipping...\n", "Processing Record 7 of Set 11 | bangalore\n", "Processing Record 8 of Set 11 | moranbah\n", "Processing Record 9 of Set 11 | lanzhou\n", "Processing Record 10 of Set 11 | majene\n", "Processing Record 11 of Set 11 | santa maria ixhuatan\n", "Processing Record 12 of Set 11 | mao\n", "Processing Record 13 of Set 11 | jizan\n", "Processing Record 14 of Set 11 | povenets\n", "Processing Record 15 of Set 11 | grenville\n", "Processing Record 16 of Set 11 | karauzyak\n", "City not found. Skipping...\n", "Processing Record 17 of Set 11 | ewa beach\n", "Processing Record 18 of Set 11 | pacific grove\n", "Processing Record 19 of Set 11 | coquimbo\n", "Processing Record 20 of Set 11 | port macquarie\n", "Processing Record 21 of Set 11 | windhoek\n", "Processing Record 22 of Set 11 | farso\n", "Processing Record 23 of Set 11 | luena\n", "Processing Record 24 of Set 11 | debno\n", "Processing Record 25 of Set 11 | poros\n", "Processing Record 26 of Set 11 | sala\n", "Processing Record 27 of Set 11 | puerto madryn\n", "Processing Record 28 of Set 11 | manado\n", "Processing Record 29 of Set 11 | kavieng\n", "Processing Record 30 of Set 11 | pontes e lacerda\n", "Processing Record 31 of Set 11 | baie-comeau\n", "Processing Record 32 of Set 11 | skjervoy\n", "Processing Record 33 of Set 11 | puerto carreno\n", "Processing Record 34 of Set 11 | riviere-au-renard\n", "Processing Record 35 of Set 11 | calbuco\n", "Processing Record 36 of Set 11 | kieta\n", "Processing Record 37 of Set 11 | belmonte\n", "Processing Record 38 of Set 11 | lar\n", "Processing Record 39 of Set 11 | tulsipur\n", "Processing Record 40 of Set 11 | bara\n", "Processing Record 41 of Set 11 | aflu\n", "City not found. Skipping...\n", "Processing Record 42 of Set 11 | lokosovo\n", "Processing Record 43 of Set 11 | nelson bay\n", "Processing Record 44 of Set 11 | valdivia\n", "Processing Record 45 of Set 11 | almaznyy\n", "Processing Record 46 of Set 11 | the valley\n", "Processing Record 47 of Set 11 | canutama\n", "Processing Record 48 of Set 11 | ulladulla\n", "Processing Record 49 of Set 11 | oktyabrskiy\n", "Processing Record 50 of Set 11 | butembo\n", "Processing Record 1 of Set 12 | choconta\n", "Processing Record 2 of Set 12 | mercedes\n", "Processing Record 3 of Set 12 | moose factory\n", "Processing Record 4 of Set 12 | hamilton\n", "Processing Record 5 of Set 12 | rio cuarto\n", "Processing Record 6 of Set 12 | uttarkashi\n", "Processing Record 7 of Set 12 | gombe\n", "Processing Record 8 of Set 12 | adrar\n", "Processing Record 9 of Set 12 | zyryanka\n", "Processing Record 10 of Set 12 | dabakala\n", "Processing Record 11 of Set 12 | padang\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Processing Record 12 of Set 12 | lasa\n", "Processing Record 13 of Set 12 | egvekinot\n", "Processing Record 14 of Set 12 | tekirdag\n", "Processing Record 15 of Set 12 | khrebtovaya\n", "Processing Record 16 of Set 12 | angoche\n", "Processing Record 17 of Set 12 | margate\n", "Processing Record 18 of Set 12 | san lawrenz\n", "Processing Record 19 of Set 12 | alabaster\n", "Processing Record 20 of Set 12 | hay river\n", "Processing Record 21 of Set 12 | ixtapa\n", "Processing Record 22 of Set 12 | nemuro\n", "Processing Record 23 of Set 12 | khangarh\n", "Processing Record 24 of Set 12 | geraldton\n", "Processing Record 25 of Set 12 | morrope\n", "Processing Record 26 of Set 12 | port lincoln\n", "Processing Record 27 of Set 12 | gravdal\n", "Processing Record 28 of Set 12 | tarakan\n", "Processing Record 29 of Set 12 | san juan de la maguana\n", "Processing Record 30 of Set 12 | waidhofen\n", "Processing Record 31 of Set 12 | alotenango\n", "Processing Record 32 of Set 12 | tefe\n", "Processing Record 33 of Set 12 | nishihara\n", "Processing Record 34 of Set 12 | makakilo city\n", "Processing Record 35 of Set 12 | el vigia\n", "Processing Record 36 of Set 12 | walvis bay\n", "Processing Record 37 of Set 12 | tallahassee\n", "Processing Record 38 of Set 12 | rungata\n", "City not found. Skipping...\n", "Processing Record 39 of Set 12 | beisfjord\n", "Processing Record 40 of Set 12 | yakima\n", "Processing Record 41 of Set 12 | kidal\n", "Processing Record 42 of Set 12 | klimovo\n", "Processing Record 43 of Set 12 | dolbeau\n", "City not found. Skipping...\n", "Processing Record 44 of Set 12 | puerto asis\n", "Processing Record 45 of Set 12 | waingapu\n", "Processing Record 46 of Set 12 | trairi\n", "Processing Record 47 of Set 12 | hihifo\n", "City not found. Skipping...\n", "Processing Record 48 of Set 12 | canyon\n", "Processing Record 49 of Set 12 | mildura\n", "Processing Record 50 of Set 12 | ojinaga\n", "Processing Record 1 of Set 13 | funadhoo\n", "Processing Record 2 of Set 13 | uhlove\n", "Processing Record 3 of Set 13 | indramayu\n", "Processing Record 4 of Set 13 | maarianhamina\n", "Processing Record 5 of Set 13 | black river\n", "Processing Record 6 of Set 13 | half moon bay\n", "Processing Record 7 of Set 13 | bubaque\n", "Processing Record 8 of Set 13 | la paz\n", "Processing Record 9 of Set 13 | tunxi\n", "City not found. Skipping...\n", "Processing Record 10 of Set 13 | faya\n", "Processing Record 11 of Set 13 | sao felix do xingu\n", "Processing Record 12 of Set 13 | tocopilla\n", "Processing Record 13 of Set 13 | sao caetano de odivelas\n", "Processing Record 14 of Set 13 | poum\n", "Processing Record 15 of Set 13 | saint-paul\n", "Processing Record 16 of Set 13 | paamiut\n", "Processing Record 17 of Set 13 | west wendover\n", "Processing Record 18 of Set 13 | port hedland\n", "Processing Record 19 of Set 13 | ostrovskoye\n", "Processing Record 20 of Set 13 | lolua\n", "City not found. Skipping...\n", "Processing Record 21 of Set 13 | luanda\n", "Processing Record 22 of Set 13 | puerto narino\n", "Processing Record 23 of Set 13 | shemgang\n", "Processing Record 24 of Set 13 | bambanglipuro\n", "Processing Record 25 of Set 13 | muyezerskiy\n", "Processing Record 26 of Set 13 | wanaka\n", "Processing Record 27 of Set 13 | salalah\n", "Processing Record 28 of Set 13 | bila tserkva\n", "Processing Record 29 of Set 13 | pyshma\n", "Processing Record 30 of Set 13 | mackay\n", "Processing Record 31 of Set 13 | san cristobal\n", "Processing Record 32 of Set 13 | roma\n", "Processing Record 33 of Set 13 | nurota\n", "Processing Record 34 of Set 13 | manjakandriana\n", "Processing Record 35 of Set 13 | nueva loja\n", "Processing Record 36 of Set 13 | canals\n", "Processing Record 37 of Set 13 | comodoro rivadavia\n", "Processing Record 38 of Set 13 | vila velha\n", "Processing Record 39 of Set 13 | nacala\n", "------------------------------------------------\n", "Data Retrieval Complete\n", "------------------------------------------------\n" ] } ], "source": [ "# List for holding reponse information\n", "lat = []\n", "temp = []\n", "temp_max = []\n", "humidity = []\n", "wind_speed = []\n", "lon = []\n", "date = []\n", "country = []\n", "cloudiness = []\n", "\n", "\n", "# Loop through the list of cities and request for data on each\n", "print(\"Beginning Data Retrieval\")\n", "print(\"--------------------------------------------\")\n", "count = 0\n", "set = 1\n", "for idx, city in enumerate(cities):\n", " count = count + 1\n", " # To avoid api call rate limits, get city weather data for 50 cities,\n", " # then sleep for 5 seconds, and then continue with next 50 cities and so on...\n", " if count == 51:\n", " count = 1\n", " set = set + 1\n", " time.sleep(5)\n", " print(f\"Processing Record {count} of Set {set} | {city}\")\n", " try:\n", " response = requests.get(query_url + city).json()\n", " lat.append(response['coord']['lat'])\n", " lon.append(response['coord']['lon'])\n", " temp.append(response['main']['temp'])\n", " temp_max.append(response['main']['temp_max'])\n", " humidity.append(response['main']['humidity'])\n", " wind_speed.append(response['wind']['speed'])\n", " date.append(response['dt'])\n", " country.append(response['sys']['country'])\n", " cloudiness.append(response['clouds']['all'])\n", " except KeyError:\n", " print(\"City not found. Skipping...\")\n", " lat.append(np.nan)\n", " lon.append(np.nan)\n", " temp.append(np.nan)\n", " temp_max.append(np.nan)\n", " humidity.append(np.nan)\n", " wind_speed.append(np.nan)\n", " date.append(np.nan)\n", " country.append(np.nan)\n", " cloudiness.append(np.nan)\n", "print(\"------------------------------------------------\")\n", "print(\"Data Retrieval Complete\")\n", "print(\"------------------------------------------------\")" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "639" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Length of Latitude and Temprature\n", "\n", "len(lat)\n", "len(temp)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Convert Raw Data to DataFrame\n", "* Export the city data into a .csv.\n", "* Display the DataFrame" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "City 585\n", "Lat 585\n", "lng 585\n", "Max Temp 585\n", "Humidity 585\n", "Cloudiness 585\n", "Wind Speed 585\n", "Country 585\n", "Date 585\n", "dtype: int64\n" ] } ], "source": [ "# Convert raw data to dataframe.\n", "city_weather_df = pd.DataFrame({\n", " \"City\": cities,\n", " \"Lat\": lat,\n", " \"lng\": lon,\n", " \"Max Temp\": temp_max,\n", " \"Humidity\": humidity,\n", " \"Cloudiness\": cloudiness,\n", " \"Wind Speed\": wind_speed,\n", " \"Country\": country,\n", " \"Date\": date,\n", "})\n", "\n", "# Drop any cities that were skipped because they could not be found using the OpenWeatherMap API.\n", "city_weather_df = city_weather_df.dropna(how=\"any\")\n", "print(city_weather_df.count())" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | City | \n", "Lat | \n", "lng | \n", "Max Temp | \n", "Humidity | \n", "Cloudiness | \n", "Wind Speed | \n", "Country | \n", "Date | \n", "
|---|---|---|---|---|---|---|---|---|---|
| 0 | \n", "severo-kurilsk | \n", "50.68 | \n", "156.12 | \n", "50.49 | \n", "78.0 | \n", "100.0 | \n", "11.39 | \n", "RU | \n", "1.592884e+09 | \n", "
| 1 | \n", "vaini | \n", "-21.20 | \n", "-175.20 | \n", "78.80 | \n", "78.0 | \n", "40.0 | \n", "10.29 | \n", "TO | \n", "1.592884e+09 | \n", "
| 2 | \n", "cidreira | \n", "-30.18 | \n", "-50.21 | \n", "64.44 | \n", "92.0 | \n", "5.0 | \n", "16.89 | \n", "BR | \n", "1.592884e+09 | \n", "
| 3 | \n", "kalmar | \n", "56.66 | \n", "16.36 | \n", "55.99 | \n", "100.0 | \n", "0.0 | \n", "3.36 | \n", "SE | \n", "1.592884e+09 | \n", "
| 4 | \n", "merauke | \n", "-8.47 | \n", "140.33 | \n", "81.84 | \n", "76.0 | \n", "20.0 | \n", "17.05 | \n", "ID | \n", "1.592884e+09 | \n", "