WeatherPy


Note

  • 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.

Observed Trends

  • The first major observable trend in the dataset for the cities generated by the uniform sampling across the full range of latitudes and longitudes for the global coordinate system is that the cities seem to be disproportionately distributed by hemisphere - that is, the northern hemisphere generally contains 65-70% of the cities i the dataset, with the remaining 30-35% located in the southern hemisphere. At first glance, this distribution seems uneven, until we take into account that most of the Earth's landmass is in the northern hemisphere, which includes approximately 71% of the world's landmass (see here). This directly corresponds to the city distribution percentages by hemisphere, cofirming that the sampled cities are distributed relatively uniformly by latitude. One would expect a 50-50 split of cities based on surface area above and below the equator, but finding a different result leads us to question why there would be such a difference, and the answer appears to be the land mass percentage for each hemisphere, since cities are primarily built on land.
  • Another trend observed is that the temperature tends to linearly increase towards the 20-degree latitude line across the northern and southern hemisphere, rather than reaching a peak at the equator. This can be accounted for by the axis tilt of the earth, which is approximately 23 degrees (see here). The r-squared values of the best fit regression lines are about -0.7 and 0.8 for the northern and southern hemispheres when comparing temperature to latitude, and if the data were separated by the 23-degree latitude instead of the equator, those correlations would likely increase (especially for the northern hemisphere, since that plot includes some data before the peak temperature is reached, muddling the linear best fit). THese r-values suggest strong linear relationships between latitude and temperature for both the northern and southern hemispheres. The 23-degree latitude line represents the points on earth closest to the sun as the northern hemisphere experiences its summer, and we can expect the -23-degree latitude to show peak temperatures for the world during the northern hemisphere's winter and the southern hemisphere's summer.
  • Finally, a trend observed from the VacationPy notebook is that the humidity values seem high across the world currently, represented by the numerous red-colored regions on the heatmap representing maximum or near-maximum humidity for the areas shown. The values seem especially high and continuous near coasts and some large bodies of water, like rivers or lakes, as compared to deeply inland areas of the continents. This is likely due to air having more evaporated water in it near the large bodies of water, which prevent the climate from becoming too arid. It would be interesting to use a statistic besides the relative humidity percentage that measures absolute humidity, like a measurement of water saturation in the air that is based on water mass per unit volume or some other absolute characteristic. The relative humidity changes based on the temperature, so air at higher temperatures can hold more water than air at lower temperatures, which would make an absolute measure of humidity show higher values for hot, wet areas like the tropics or rainforests as opposed to dryer or more temperate areas that still have a relatively high relative humidity. That might be a way to improve these notebooks for the next version, so that the humidity heat map give us further insights - but those calculations are currently out of the scope of this project.
In [4]:
# Dependencies and Setup
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import requests
import time
from scipy.stats import linregress
import json
import datetime

# Import API key
from api_keys import weather_api_key

# Incorporated citipy to determine city based on latitude and longitude
from citipy import citipy

# Output File (CSV)
output_data_file = "output_data/cities.csv"

# Range of latitudes and longitudes
lat_range = (-90, 90)
lng_range = (-180, 180)

Generate Cities List

In [5]:
# List for holding lat_lngs and cities
lat_lngs = []
cities = []

# Create a set of random lat and lng combinations
lats = np.random.uniform(lat_range[0], lat_range[1], size=1500)
lngs = np.random.uniform(lng_range[0], lng_range[1], size=1500)
lat_lngs = zip(lats, lngs)

saved_lats = []
saved_longs = []

# Identify nearest city for each lat, lng combination
for lat_lng in lat_lngs:
    city = citipy.nearest_city(lat_lng[0], lat_lng[1]).city_name
    
    # If the city is unique, then add it to a our cities list
    #also add estimated latitude and longitude
    if city not in cities:
        cities.append(city)
        saved_lats.append(lat_lng[0])
        saved_longs.append(lat_lng[1])
        
# print(citipy.nearest_city(0, 0).keys())

# Print the city count to confirm sufficient count
print("{} cities have been identified to poll for weather".format(len(cities)))

city_list = pd.DataFrame({"City":cities, "Approx. Latitude":saved_lats, "Approx. Longitude":saved_longs})
# city_list = pd.DataFrame({"City":cities})

#save to a csv (for reference - can compare estimated coordinates to actual coordinates if there is time, which cannot be done
#easily with citipy because the references only go one way -> approx. coordinates to city name, not city name to actual 
#coordinates)
city_list.to_csv("./CityNameList.csv")
city_list.head()
605 cities have been identified to poll for weather
Out[5]:
City Approx. Latitude Approx. Longitude
0 kloulklubed 3.222335 133.336777
1 rikitea -54.497065 -112.746685
2 hami 39.870623 91.887579
3 terrace bay 48.853837 -88.185405
4 saldanha -40.961281 -3.791138

Perform API Calls

  • Perform a weather check on each city using a series of successive API calls.
  • Include a print log of each city as it'sbeing processed (with the city number and city name).
In [6]:
#url for advanced mapping using OpenWeatherMap's new OneCall API to get historical weather info by coordinates instead of 
#city names - not implemented for project initially due to setup being different
# base_url = "https://api.openweathermap.org/data/2.5/onecall?lat={lat}&lon={lon}&exclude={part}&appid={YOUR API KEY}"
# params = {"exclude":"minutely,hourly,current", "appid":weather_api_key, "lat":city_list["Latitude"][0], 
#           "lon":city_list["Longitude"][0]}

#setup columns for temperature, humidity, cloudiness, and wind speed
city_list["Max Temperature (F)"] = ""
city_list["Humidity (%)"] = ""
city_list["Cloudiness"] = ""
city_list["Wind Speed (mph)"] = ""

#setup columns for actual latitude and longitude
city_list["Actual Latitude"] = ""
city_list["Actual Longitude"] = ""

#setup column for country code
city_list["Country"] = ""

#setup column for city datetime
city_list["Datetime (Local)"] = ""
#note that current timezone is PST (-7:00 from GMT)
PST_offset = 7*60*60


base_url_current = "http://api.openweathermap.org/data/2.5/weather"
params = {"q":city_list["City"][0], "units":"imperial", "appid":weather_api_key}

test_response = requests.get(base_url_current, params)
json_response = test_response.json()
# json.dumps(json_response, indent=4)


#establish pattern for getting data into columns from json object
city_list["Actual Latitude"][0] = json_response["coord"]["lat"]
city_list["Actual Longitude"][0] = json_response["coord"]["lon"]
city_list["Max Temperature (F)"][0] = json_response["main"]["temp_max"]
city_list["Humidity (%)"][0] = json_response["main"]["humidity"]
city_list["Cloudiness"][0] = json_response["clouds"]["all"]
city_list["Wind Speed (mph)"][0] = json_response["wind"]["speed"]
city_list["Country"][0] = json_response["sys"]["country"]
#create datetime.datetime object to give local date and time at the city of interest (need to add an offset from our 
#computer clock set to PST and then add in the timezone shift given by the API to change from GMT)
first_city_time = datetime.datetime.fromtimestamp(json_response["dt"]+json_response["timezone"]+PST_offset)
city_list["Datetime (Local)"][0] = first_city_time.strftime("%m/%d/%Y, %H:%M:%S")

#create helper function to give the Datetime (UTC) column string
def getTimeString(resp_json, comp_time):
    curr_city_datetime = datetime.datetime.fromtimestamp(resp_json["dt"]+resp_json["timezone"]+comp_time)
    return curr_city_datetime.strftime("%m/%d/%Y, %H:%M:%S")

#create function to add all info to dataframe using the above pattern 
def addColumns(pd_df, resp_json, i, comp_time):
    pd_df["Actual Latitude"][i] = resp_json["coord"]["lat"]
    pd_df["Actual Longitude"][i] = resp_json["coord"]["lon"]
    pd_df["Max Temperature (F)"][i] = resp_json["main"]["temp_max"]
    pd_df["Humidity (%)"][i] = resp_json["main"]["humidity"]
    pd_df["Cloudiness"][i] = resp_json["clouds"]["all"]
    pd_df["Wind Speed (mph)"][i] = resp_json["wind"]["speed"]
    pd_df["Country"][i] = resp_json["sys"]["country"]
    #create datetime.datetime object to give local date and time at the city of interest (need to add an offset from our 
    #computer clock set to PST and then add in the timezone shift given by the API to change from GMT)
    #change it to a string to keep the timestamp the same in case it is examined later
    pd_df["Datetime (Local)"][i] = getTimeString(resp_json, comp_time)
        
C:\Users\patri\anaconda3\lib\site-packages\ipykernel_launcher.py:35: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
C:\Users\patri\anaconda3\lib\site-packages\ipykernel_launcher.py:36: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
C:\Users\patri\anaconda3\lib\site-packages\ipykernel_launcher.py:37: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
C:\Users\patri\anaconda3\lib\site-packages\ipykernel_launcher.py:38: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
C:\Users\patri\anaconda3\lib\site-packages\ipykernel_launcher.py:39: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
C:\Users\patri\anaconda3\lib\site-packages\ipykernel_launcher.py:40: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
C:\Users\patri\anaconda3\lib\site-packages\ipykernel_launcher.py:41: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
C:\Users\patri\anaconda3\lib\site-packages\ipykernel_launcher.py:45: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
In [7]:
#loop over rows in dataframe to gather info for each city's weather
#put in its own cell to allow running separately from the test/setup of the API calls
record_count = len(city_list)

for i, row in city_list.iterrows():
    #use try/except construct to skip over missing cities or missing info
    try:
        params["q"] = row["City"]
        response = requests.get(base_url_current, params)
        json_resp = response.json()
        addColumns(city_list, json_resp, i, PST_offset)
        print("Retrieved record {} of {} for the city of {}".format(i+1, record_count, row["City"]))
    except:
        city_list["City"][i] = "Failed!!!"
        print("Could not retrieve record {} of {} for the city of {}".format(i+1, record_count, row["City"]))
        

city_list.head()
C:\Users\patri\anaconda3\lib\site-packages\ipykernel_launcher.py:54: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
C:\Users\patri\anaconda3\lib\site-packages\ipykernel_launcher.py:55: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
C:\Users\patri\anaconda3\lib\site-packages\ipykernel_launcher.py:56: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
C:\Users\patri\anaconda3\lib\site-packages\ipykernel_launcher.py:57: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
C:\Users\patri\anaconda3\lib\site-packages\ipykernel_launcher.py:58: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
C:\Users\patri\anaconda3\lib\site-packages\ipykernel_launcher.py:59: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
C:\Users\patri\anaconda3\lib\site-packages\ipykernel_launcher.py:60: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
C:\Users\patri\anaconda3\lib\site-packages\ipykernel_launcher.py:64: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
Retrieved record 1 of 605 for the city of kloulklubed
Retrieved record 2 of 605 for the city of rikitea
Retrieved record 3 of 605 for the city of hami
Retrieved record 4 of 605 for the city of terrace bay
Retrieved record 5 of 605 for the city of saldanha
Retrieved record 6 of 605 for the city of knysna
Retrieved record 7 of 605 for the city of ubinskoye
Retrieved record 8 of 605 for the city of berlevag
Retrieved record 9 of 605 for the city of punta arenas
Retrieved record 10 of 605 for the city of vaini
Retrieved record 11 of 605 for the city of ushuaia
Retrieved record 12 of 605 for the city of beringovskiy
Retrieved record 13 of 605 for the city of butaritari
Retrieved record 14 of 605 for the city of merrill
Retrieved record 15 of 605 for the city of cherskiy
Retrieved record 16 of 605 for the city of cayenne
Retrieved record 17 of 605 for the city of barddhaman
Retrieved record 18 of 605 for the city of kapaa
Retrieved record 19 of 605 for the city of leningradskiy
Retrieved record 20 of 605 for the city of yellowknife
Retrieved record 21 of 605 for the city of port alfred
Retrieved record 22 of 605 for the city of alofi
Retrieved record 23 of 605 for the city of bonavista
Retrieved record 24 of 605 for the city of mataura
Could not retrieve record 25 of 605 for the city of cockburn harbour
C:\Users\patri\anaconda3\lib\site-packages\ipykernel_launcher.py:14: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  
Retrieved record 26 of 605 for the city of tiznit
Retrieved record 27 of 605 for the city of banjar
Retrieved record 28 of 605 for the city of hobart
Retrieved record 29 of 605 for the city of sao filipe
Retrieved record 30 of 605 for the city of lebu
Retrieved record 31 of 605 for the city of kostino
Retrieved record 32 of 605 for the city of eyl
Retrieved record 33 of 605 for the city of nome
Retrieved record 34 of 605 for the city of new norfolk
Retrieved record 35 of 605 for the city of praia
Retrieved record 36 of 605 for the city of qaanaaq
Retrieved record 37 of 605 for the city of basco
Retrieved record 38 of 605 for the city of alyangula
Retrieved record 39 of 605 for the city of hilo
Retrieved record 40 of 605 for the city of peniche
Retrieved record 41 of 605 for the city of georgetown
Could not retrieve record 42 of 605 for the city of kasra
Retrieved record 43 of 605 for the city of acapulco
Retrieved record 44 of 605 for the city of rio grande
Retrieved record 45 of 605 for the city of clyde river
Retrieved record 46 of 605 for the city of benton harbor
Retrieved record 47 of 605 for the city of carnarvon
Retrieved record 48 of 605 for the city of cabo san lucas
Retrieved record 49 of 605 for the city of hare bay
Retrieved record 50 of 605 for the city of tyumentsevo
Retrieved record 51 of 605 for the city of maniitsoq
Retrieved record 52 of 605 for the city of bluff
Could not retrieve record 53 of 605 for the city of ksenyevka
Retrieved record 54 of 605 for the city of gambela
Retrieved record 55 of 605 for the city of batagay
Could not retrieve record 56 of 605 for the city of tabiauea
Could not retrieve record 57 of 605 for the city of illoqqortoormiut
Retrieved record 58 of 605 for the city of guzelyurt
Retrieved record 59 of 605 for the city of fortuna
Retrieved record 60 of 605 for the city of upernavik
Retrieved record 61 of 605 for the city of poltavka
Retrieved record 62 of 605 for the city of jalu
Could not retrieve record 63 of 605 for the city of bandar penggaram
Could not retrieve record 64 of 605 for the city of kazalinsk
Retrieved record 65 of 605 for the city of gandorhun
Retrieved record 66 of 605 for the city of victoria
Retrieved record 67 of 605 for the city of arraial do cabo
Retrieved record 68 of 605 for the city of provideniya
Could not retrieve record 69 of 605 for the city of mys shmidta
Retrieved record 70 of 605 for the city of tutoia
Retrieved record 71 of 605 for the city of grindavik
Retrieved record 72 of 605 for the city of sistranda
Retrieved record 73 of 605 for the city of salalah
Retrieved record 74 of 605 for the city of nikolskoye
Could not retrieve record 75 of 605 for the city of hihifo
Retrieved record 76 of 605 for the city of saint george
Retrieved record 77 of 605 for the city of mahebourg
Retrieved record 78 of 605 for the city of grenfell
Could not retrieve record 79 of 605 for the city of yian
Retrieved record 80 of 605 for the city of monroe
Retrieved record 81 of 605 for the city of saint-philippe
Retrieved record 82 of 605 for the city of jamestown
Retrieved record 83 of 605 for the city of kawasaki
Retrieved record 84 of 605 for the city of briancon
Retrieved record 85 of 605 for the city of cape town
Retrieved record 86 of 605 for the city of vao
Could not retrieve record 87 of 605 for the city of grand river south east
Retrieved record 88 of 605 for the city of macheng
Retrieved record 89 of 605 for the city of zhezkazgan
Retrieved record 90 of 605 for the city of san felipe
Retrieved record 91 of 605 for the city of sobolevo
Retrieved record 92 of 605 for the city of leshukonskoye
Could not retrieve record 93 of 605 for the city of samusu
Retrieved record 94 of 605 for the city of marawi
Retrieved record 95 of 605 for the city of bontang
Retrieved record 96 of 605 for the city of izhma
Retrieved record 97 of 605 for the city of leh
Retrieved record 98 of 605 for the city of albany
Retrieved record 99 of 605 for the city of taltal
Retrieved record 100 of 605 for the city of juneau
Retrieved record 101 of 605 for the city of meulaboh
Retrieved record 102 of 605 for the city of nusaybin
Could not retrieve record 103 of 605 for the city of taolanaro
Retrieved record 104 of 605 for the city of bredasdorp
Retrieved record 105 of 605 for the city of atuona
Retrieved record 106 of 605 for the city of ozernovskiy
Retrieved record 107 of 605 for the city of luderitz
Retrieved record 108 of 605 for the city of hermanus
Retrieved record 109 of 605 for the city of busselton
Retrieved record 110 of 605 for the city of thompson
Retrieved record 111 of 605 for the city of sibolga
Could not retrieve record 112 of 605 for the city of barentsburg
Retrieved record 113 of 605 for the city of warah
Retrieved record 114 of 605 for the city of desaguadero
Retrieved record 115 of 605 for the city of dikson
Retrieved record 116 of 605 for the city of muskegon
Retrieved record 117 of 605 for the city of gushikawa
Could not retrieve record 118 of 605 for the city of belushya guba
Retrieved record 119 of 605 for the city of coihaique
Retrieved record 120 of 605 for the city of namibe
Retrieved record 121 of 605 for the city of severo-kurilsk
Retrieved record 122 of 605 for the city of valley city
Retrieved record 123 of 605 for the city of kumbo
Retrieved record 124 of 605 for the city of castro
Retrieved record 125 of 605 for the city of tucurui
Retrieved record 126 of 605 for the city of aloleng
Retrieved record 127 of 605 for the city of nampula
Retrieved record 128 of 605 for the city of pangody
Retrieved record 129 of 605 for the city of shitanjing
Retrieved record 130 of 605 for the city of bilibino
Could not retrieve record 131 of 605 for the city of dolbeau
Retrieved record 132 of 605 for the city of mikuni
Could not retrieve record 133 of 605 for the city of attawapiskat
Could not retrieve record 134 of 605 for the city of senmonorom
Retrieved record 135 of 605 for the city of puerto ayora
Retrieved record 136 of 605 for the city of lorengau
Retrieved record 137 of 605 for the city of gweta
Retrieved record 138 of 605 for the city of kruisfontein
Retrieved record 139 of 605 for the city of grand-santi
Retrieved record 140 of 605 for the city of cap malheureux
Retrieved record 141 of 605 for the city of khvalynsk
Retrieved record 142 of 605 for the city of sisimiut
Retrieved record 143 of 605 for the city of zhaozhou
Retrieved record 144 of 605 for the city of esperance
Retrieved record 145 of 605 for the city of port elizabeth
Retrieved record 146 of 605 for the city of hasaki
Could not retrieve record 147 of 605 for the city of yanan
Retrieved record 148 of 605 for the city of ribeira grande
Retrieved record 149 of 605 for the city of saskylakh
Retrieved record 150 of 605 for the city of chuy
Retrieved record 151 of 605 for the city of winnemucca
Retrieved record 152 of 605 for the city of kavieng
Retrieved record 153 of 605 for the city of constitucion
Retrieved record 154 of 605 for the city of alenquer
Retrieved record 155 of 605 for the city of ketchikan
Retrieved record 156 of 605 for the city of rivadavia
Retrieved record 157 of 605 for the city of mishelevka
Retrieved record 158 of 605 for the city of cedar city
Retrieved record 159 of 605 for the city of lindenhurst
Retrieved record 160 of 605 for the city of labuhan
Retrieved record 161 of 605 for the city of airai
Retrieved record 162 of 605 for the city of anadyr
Retrieved record 163 of 605 for the city of sao mateus do maranhao
Retrieved record 164 of 605 for the city of upanema
Retrieved record 165 of 605 for the city of haines junction
Retrieved record 166 of 605 for the city of januaria
Retrieved record 167 of 605 for the city of mar del plata
Retrieved record 168 of 605 for the city of kodiak
Retrieved record 169 of 605 for the city of doraha
Retrieved record 170 of 605 for the city of waingapu
Retrieved record 171 of 605 for the city of tibati
Retrieved record 172 of 605 for the city of pafos
Retrieved record 173 of 605 for the city of sochaczew
Retrieved record 174 of 605 for the city of kangaatsiaq
Retrieved record 175 of 605 for the city of maues
Retrieved record 176 of 605 for the city of korla
Retrieved record 177 of 605 for the city of hervey bay
Retrieved record 178 of 605 for the city of margate
Retrieved record 179 of 605 for the city of malanje
Could not retrieve record 180 of 605 for the city of samalaeulu
Could not retrieve record 181 of 605 for the city of marcona
Retrieved record 182 of 605 for the city of batticaloa
Could not retrieve record 183 of 605 for the city of saleaula
Retrieved record 184 of 605 for the city of hithadhoo
Retrieved record 185 of 605 for the city of pevek
Could not retrieve record 186 of 605 for the city of vaitupu
Retrieved record 187 of 605 for the city of iralaya
Retrieved record 188 of 605 for the city of arman
Retrieved record 189 of 605 for the city of san cristobal
Retrieved record 190 of 605 for the city of te anau
Retrieved record 191 of 605 for the city of east london
Retrieved record 192 of 605 for the city of namatanai
Retrieved record 193 of 605 for the city of vintileasca
Retrieved record 194 of 605 for the city of copiapo
Retrieved record 195 of 605 for the city of port lincoln
Retrieved record 196 of 605 for the city of adiake
Retrieved record 197 of 605 for the city of codrington
Retrieved record 198 of 605 for the city of khuzhir
Retrieved record 199 of 605 for the city of fort-shevchenko
Retrieved record 200 of 605 for the city of boden
Retrieved record 201 of 605 for the city of baghdad
Retrieved record 202 of 605 for the city of kortkeros
Retrieved record 203 of 605 for the city of los alamos
Retrieved record 204 of 605 for the city of morant bay
Retrieved record 205 of 605 for the city of la ronge
Retrieved record 206 of 605 for the city of praya
Retrieved record 207 of 605 for the city of barrow
Retrieved record 208 of 605 for the city of tianpeng
Could not retrieve record 209 of 605 for the city of artyk
Retrieved record 210 of 605 for the city of souillac
Retrieved record 211 of 605 for the city of cosala
Retrieved record 212 of 605 for the city of klaipeda
Could not retrieve record 213 of 605 for the city of jiddah
Retrieved record 214 of 605 for the city of port macquarie
Retrieved record 215 of 605 for the city of valparaiso
Retrieved record 216 of 605 for the city of irpa irpa
Retrieved record 217 of 605 for the city of trairi
Retrieved record 218 of 605 for the city of sinnar
Retrieved record 219 of 605 for the city of bethel
Retrieved record 220 of 605 for the city of kahului
Retrieved record 221 of 605 for the city of chiang kham
Retrieved record 222 of 605 for the city of umm kaddadah
Retrieved record 223 of 605 for the city of ahipara
Retrieved record 224 of 605 for the city of haimen
Retrieved record 225 of 605 for the city of sept-iles
Could not retrieve record 226 of 605 for the city of khagrachari
Retrieved record 227 of 605 for the city of kutum
Retrieved record 228 of 605 for the city of kaitangata
Retrieved record 229 of 605 for the city of fuxin
Retrieved record 230 of 605 for the city of noormarkku
Retrieved record 231 of 605 for the city of komsomolskiy
Retrieved record 232 of 605 for the city of dakar
Retrieved record 233 of 605 for the city of petrokamenskoye
Retrieved record 234 of 605 for the city of touros
Retrieved record 235 of 605 for the city of dalhousie
Retrieved record 236 of 605 for the city of caravelas
Could not retrieve record 237 of 605 for the city of toliary
Retrieved record 238 of 605 for the city of novobirilyussy
Retrieved record 239 of 605 for the city of klaksvik
Retrieved record 240 of 605 for the city of hibbing
Retrieved record 241 of 605 for the city of bambous virieux
Retrieved record 242 of 605 for the city of sur
Retrieved record 243 of 605 for the city of cidreira
Retrieved record 244 of 605 for the city of veraval
Retrieved record 245 of 605 for the city of srandakan
Retrieved record 246 of 605 for the city of humberto de campos
Retrieved record 247 of 605 for the city of coari
Could not retrieve record 248 of 605 for the city of nizhneyansk
Retrieved record 249 of 605 for the city of sao joao da barra
Retrieved record 250 of 605 for the city of grand forks
Retrieved record 251 of 605 for the city of kropotkin
Retrieved record 252 of 605 for the city of port moresby
Retrieved record 253 of 605 for the city of burnie
Retrieved record 254 of 605 for the city of belyy yar
Retrieved record 255 of 605 for the city of joao camara
Retrieved record 256 of 605 for the city of plettenberg bay
Retrieved record 257 of 605 for the city of maryville
Could not retrieve record 258 of 605 for the city of ituni
Retrieved record 259 of 605 for the city of russell
Retrieved record 260 of 605 for the city of tucuman
Retrieved record 261 of 605 for the city of kiunga
Retrieved record 262 of 605 for the city of payson
Retrieved record 263 of 605 for the city of poum
Retrieved record 264 of 605 for the city of olonets
Could not retrieve record 265 of 605 for the city of lolua
Retrieved record 266 of 605 for the city of hofn
Retrieved record 267 of 605 for the city of oksfjord
Retrieved record 268 of 605 for the city of zaragoza
Retrieved record 269 of 605 for the city of roebourne
Retrieved record 270 of 605 for the city of shenjiamen
Retrieved record 271 of 605 for the city of samarai
Retrieved record 272 of 605 for the city of kapit
Retrieved record 273 of 605 for the city of westport
Retrieved record 274 of 605 for the city of chapais
Retrieved record 275 of 605 for the city of berbera
Retrieved record 276 of 605 for the city of siilinjarvi
Retrieved record 277 of 605 for the city of iqaluit
Retrieved record 278 of 605 for the city of abu kamal
Retrieved record 279 of 605 for the city of tezu
Retrieved record 280 of 605 for the city of husavik
Retrieved record 281 of 605 for the city of havre-saint-pierre
Retrieved record 282 of 605 for the city of luwingu
Retrieved record 283 of 605 for the city of longyearbyen
Retrieved record 284 of 605 for the city of morondava
Retrieved record 285 of 605 for the city of sitka
Retrieved record 286 of 605 for the city of eydhafushi
Retrieved record 287 of 605 for the city of saint-marc
Retrieved record 288 of 605 for the city of akdepe
Retrieved record 289 of 605 for the city of tiksi
Retrieved record 290 of 605 for the city of itoman
Retrieved record 291 of 605 for the city of tuktoyaktuk
Retrieved record 292 of 605 for the city of khatanga
Retrieved record 293 of 605 for the city of batu arang
Retrieved record 294 of 605 for the city of cairns
Retrieved record 295 of 605 for the city of pizarro
Retrieved record 296 of 605 for the city of rio gallegos
Could not retrieve record 297 of 605 for the city of degirmen
Retrieved record 298 of 605 for the city of biltine
Retrieved record 299 of 605 for the city of thinadhoo
Retrieved record 300 of 605 for the city of cockburn town
Retrieved record 301 of 605 for the city of tasiilaq
Retrieved record 302 of 605 for the city of baltasi
Retrieved record 303 of 605 for the city of sao gabriel da cachoeira
Retrieved record 304 of 605 for the city of toktogul
Retrieved record 305 of 605 for the city of talcahuano
Retrieved record 306 of 605 for the city of malakal
Retrieved record 307 of 605 for the city of laguna
Retrieved record 308 of 605 for the city of dingle
Retrieved record 309 of 605 for the city of sile
Retrieved record 310 of 605 for the city of bogorodskoye
Retrieved record 311 of 605 for the city of ahmadnagar
Retrieved record 312 of 605 for the city of necochea
Retrieved record 313 of 605 for the city of lillesand
Retrieved record 314 of 605 for the city of kislovodsk
Retrieved record 315 of 605 for the city of ndele
Retrieved record 316 of 605 for the city of mildura
Retrieved record 317 of 605 for the city of khani
Retrieved record 318 of 605 for the city of balikpapan
Retrieved record 319 of 605 for the city of san rafael
Retrieved record 320 of 605 for the city of avarua
Retrieved record 321 of 605 for the city of ponta do sol
Retrieved record 322 of 605 for the city of lebork
Retrieved record 323 of 605 for the city of ilulissat
Retrieved record 324 of 605 for the city of campbell river
Retrieved record 325 of 605 for the city of harper
Retrieved record 326 of 605 for the city of lardos
Retrieved record 327 of 605 for the city of salumbar
Retrieved record 328 of 605 for the city of zhuanghe
Retrieved record 329 of 605 for the city of pochutla
Retrieved record 330 of 605 for the city of demba
Retrieved record 331 of 605 for the city of panama city
Could not retrieve record 332 of 605 for the city of tumannyy
Retrieved record 333 of 605 for the city of ternate
Retrieved record 334 of 605 for the city of inverness
Retrieved record 335 of 605 for the city of kristianstad
Retrieved record 336 of 605 for the city of chokurdakh
Retrieved record 337 of 605 for the city of fredericksburg
Retrieved record 338 of 605 for the city of sassandra
Retrieved record 339 of 605 for the city of dudinka
Retrieved record 340 of 605 for the city of vanavara
Retrieved record 341 of 605 for the city of yulara
Retrieved record 342 of 605 for the city of weston-super-mare
Retrieved record 343 of 605 for the city of bilma
Retrieved record 344 of 605 for the city of santiago del estero
Retrieved record 345 of 605 for the city of narrabri
Retrieved record 346 of 605 for the city of lompoc
Retrieved record 347 of 605 for the city of koungou
Retrieved record 348 of 605 for the city of baykit
Retrieved record 349 of 605 for the city of solnechnyy
Retrieved record 350 of 605 for the city of nhulunbuy
Retrieved record 351 of 605 for the city of trincomalee
Could not retrieve record 352 of 605 for the city of umzimvubu
Retrieved record 353 of 605 for the city of santa helena de goias
Retrieved record 354 of 605 for the city of havre
Could not retrieve record 355 of 605 for the city of malakisi
Retrieved record 356 of 605 for the city of saint-jovite
Retrieved record 357 of 605 for the city of vanimo
Retrieved record 358 of 605 for the city of viedma
Could not retrieve record 359 of 605 for the city of sentyabrskiy
Retrieved record 360 of 605 for the city of akyab
Retrieved record 361 of 605 for the city of progreso
Could not retrieve record 362 of 605 for the city of gulshat
Retrieved record 363 of 605 for the city of zhigansk
Retrieved record 364 of 605 for the city of dicabisagan
Retrieved record 365 of 605 for the city of puerto carreno
Retrieved record 366 of 605 for the city of opuwo
Retrieved record 367 of 605 for the city of chiredzi
Retrieved record 368 of 605 for the city of banda aceh
Retrieved record 369 of 605 for the city of imbituba
Retrieved record 370 of 605 for the city of murray bridge
Retrieved record 371 of 605 for the city of high level
Retrieved record 372 of 605 for the city of houma
Retrieved record 373 of 605 for the city of lerwick
Retrieved record 374 of 605 for the city of marienburg
Retrieved record 375 of 605 for the city of tura
Retrieved record 376 of 605 for the city of mount isa
Retrieved record 377 of 605 for the city of paciran
Retrieved record 378 of 605 for the city of noumea
Retrieved record 379 of 605 for the city of fairview
Retrieved record 380 of 605 for the city of wanning
Retrieved record 381 of 605 for the city of carballo
Retrieved record 382 of 605 for the city of nanortalik
Retrieved record 383 of 605 for the city of beaver dam
Retrieved record 384 of 605 for the city of pacific grove
Retrieved record 385 of 605 for the city of storm lake
Retrieved record 386 of 605 for the city of bam
Retrieved record 387 of 605 for the city of port hedland
Retrieved record 388 of 605 for the city of masuguru
Retrieved record 389 of 605 for the city of tanabe
Retrieved record 390 of 605 for the city of srednekolymsk
Retrieved record 391 of 605 for the city of saint-joseph
Retrieved record 392 of 605 for the city of bosaso
Retrieved record 393 of 605 for the city of iquitos
Retrieved record 394 of 605 for the city of buala
Could not retrieve record 395 of 605 for the city of phan rang
Retrieved record 396 of 605 for the city of mandalgovi
Retrieved record 397 of 605 for the city of lenger
Retrieved record 398 of 605 for the city of eureka
Retrieved record 399 of 605 for the city of inhambane
Retrieved record 400 of 605 for the city of san quintin
Retrieved record 401 of 605 for the city of natal
Could not retrieve record 402 of 605 for the city of kuche
Retrieved record 403 of 605 for the city of vestmannaeyjar
Retrieved record 404 of 605 for the city of yasnyy
Retrieved record 405 of 605 for the city of vizinga
Retrieved record 406 of 605 for the city of hauterive
Retrieved record 407 of 605 for the city of mahibadhoo
Retrieved record 408 of 605 for the city of palora
Retrieved record 409 of 605 for the city of ibra
Retrieved record 410 of 605 for the city of fereydunshahr
Retrieved record 411 of 605 for the city of high prairie
Retrieved record 412 of 605 for the city of riyadh
Retrieved record 413 of 605 for the city of faanui
Retrieved record 414 of 605 for the city of corinto
Retrieved record 415 of 605 for the city of ponta delgada
Retrieved record 416 of 605 for the city of revda
Retrieved record 417 of 605 for the city of borujerd
Retrieved record 418 of 605 for the city of port blair
Retrieved record 419 of 605 for the city of hjelset
Retrieved record 420 of 605 for the city of kurtamysh
Retrieved record 421 of 605 for the city of sayville
Retrieved record 422 of 605 for the city of shangrao
Retrieved record 423 of 605 for the city of shimoda
Retrieved record 424 of 605 for the city of shache
Retrieved record 425 of 605 for the city of pokhara
Retrieved record 426 of 605 for the city of mount abu
Retrieved record 427 of 605 for the city of amberley
Could not retrieve record 428 of 605 for the city of amderma
Retrieved record 429 of 605 for the city of tuatapere
Retrieved record 430 of 605 for the city of tilichiki
Retrieved record 431 of 605 for the city of panzhihua
Retrieved record 432 of 605 for the city of quatre cocos
Retrieved record 433 of 605 for the city of tromso
Retrieved record 434 of 605 for the city of katsuura
Retrieved record 435 of 605 for the city of panalingaan
Retrieved record 436 of 605 for the city of udachnyy
Retrieved record 437 of 605 for the city of dankov
Retrieved record 438 of 605 for the city of rocha
Retrieved record 439 of 605 for the city of umiray
Retrieved record 440 of 605 for the city of mitsamiouli
Retrieved record 441 of 605 for the city of siniscola
Retrieved record 442 of 605 for the city of idah
Retrieved record 443 of 605 for the city of salgar
Retrieved record 444 of 605 for the city of palmer
Retrieved record 445 of 605 for the city of kununurra
Retrieved record 446 of 605 for the city of talnakh
Retrieved record 447 of 605 for the city of kidal
Retrieved record 448 of 605 for the city of maiduguri
Retrieved record 449 of 605 for the city of maceio
Retrieved record 450 of 605 for the city of asau
Retrieved record 451 of 605 for the city of xining
Retrieved record 452 of 605 for the city of iskateley
Retrieved record 453 of 605 for the city of brejinho
Retrieved record 454 of 605 for the city of ixtapa
Retrieved record 455 of 605 for the city of parabel
Retrieved record 456 of 605 for the city of geraldton
Retrieved record 457 of 605 for the city of bentiu
Retrieved record 458 of 605 for the city of inca
Retrieved record 459 of 605 for the city of monrovia
Retrieved record 460 of 605 for the city of los llanos de aridane
Retrieved record 461 of 605 for the city of yeppoon
Retrieved record 462 of 605 for the city of padang
Retrieved record 463 of 605 for the city of teahupoo
Retrieved record 464 of 605 for the city of zhengjiatun
Retrieved record 465 of 605 for the city of tanga
Retrieved record 466 of 605 for the city of kesova gora
Retrieved record 467 of 605 for the city of anchorage
Retrieved record 468 of 605 for the city of khromtau
Retrieved record 469 of 605 for the city of teguise
Retrieved record 470 of 605 for the city of berezovyy
Retrieved record 471 of 605 for the city of pyay
Retrieved record 472 of 605 for the city of muroto
Retrieved record 473 of 605 for the city of gerash
Retrieved record 474 of 605 for the city of sorland
Retrieved record 475 of 605 for the city of shingu
Retrieved record 476 of 605 for the city of marsh harbour
Retrieved record 477 of 605 for the city of phoenix
Retrieved record 478 of 605 for the city of bani walid
Retrieved record 479 of 605 for the city of rabo de peixe
Retrieved record 480 of 605 for the city of kulhudhuffushi
Retrieved record 481 of 605 for the city of dembi dolo
Retrieved record 482 of 605 for the city of alexandroupoli
Retrieved record 483 of 605 for the city of bathsheba
Retrieved record 484 of 605 for the city of saint marys
Retrieved record 485 of 605 for the city of chapada dos guimaraes
Retrieved record 486 of 605 for the city of adrar
Retrieved record 487 of 605 for the city of faya
Could not retrieve record 488 of 605 for the city of palaiopirgos
Could not retrieve record 489 of 605 for the city of sorvag
Retrieved record 490 of 605 for the city of fare
Could not retrieve record 491 of 605 for the city of grand centre
Retrieved record 492 of 605 for the city of churapcha
Retrieved record 493 of 605 for the city of bandarbeyla
Retrieved record 494 of 605 for the city of pecos
Retrieved record 495 of 605 for the city of linxi
Retrieved record 496 of 605 for the city of naryan-mar
Retrieved record 497 of 605 for the city of zaysan
Retrieved record 498 of 605 for the city of fairbanks
Retrieved record 499 of 605 for the city of atambua
Retrieved record 500 of 605 for the city of ojinaga
Retrieved record 501 of 605 for the city of murgab
Retrieved record 502 of 605 for the city of andenes
Retrieved record 503 of 605 for the city of deputatskiy
Retrieved record 504 of 605 for the city of ouallam
Retrieved record 505 of 605 for the city of qeshm
Retrieved record 506 of 605 for the city of strezhevoy
Retrieved record 507 of 605 for the city of guarapari
Retrieved record 508 of 605 for the city of ingham
Retrieved record 509 of 605 for the city of japura
Retrieved record 510 of 605 for the city of doume
Retrieved record 511 of 605 for the city of north bend
Retrieved record 512 of 605 for the city of hay river
Could not retrieve record 513 of 605 for the city of doctor pedro p. pena
Could not retrieve record 514 of 605 for the city of mrirt
Retrieved record 515 of 605 for the city of tessalit
Retrieved record 516 of 605 for the city of lixourion
Retrieved record 517 of 605 for the city of kavaratti
Retrieved record 518 of 605 for the city of ibimirim
Retrieved record 519 of 605 for the city of abu zabad
Retrieved record 520 of 605 for the city of ola
Retrieved record 521 of 605 for the city of alibag
Retrieved record 522 of 605 for the city of buta
Could not retrieve record 523 of 605 for the city of labutta
Retrieved record 524 of 605 for the city of saint-georges
Retrieved record 525 of 605 for the city of pelotas
Retrieved record 526 of 605 for the city of vostok
Retrieved record 527 of 605 for the city of shakiso
Retrieved record 528 of 605 for the city of tabas
Retrieved record 529 of 605 for the city of grand gaube
Retrieved record 530 of 605 for the city of broken hill
Retrieved record 531 of 605 for the city of chumikan
Retrieved record 532 of 605 for the city of hirara
Retrieved record 533 of 605 for the city of scarborough
Could not retrieve record 534 of 605 for the city of bur gabo
Retrieved record 535 of 605 for the city of charlestown
Retrieved record 536 of 605 for the city of fort nelson
Could not retrieve record 537 of 605 for the city of palkaka
Retrieved record 538 of 605 for the city of pisco
Retrieved record 539 of 605 for the city of vallenar
Retrieved record 540 of 605 for the city of terney
Retrieved record 541 of 605 for the city of vila franca do campo
Retrieved record 542 of 605 for the city of trapani
Retrieved record 543 of 605 for the city of ossipee
Retrieved record 544 of 605 for the city of alekseyevka
Retrieved record 545 of 605 for the city of micheweni
Retrieved record 546 of 605 for the city of yinchuan
Retrieved record 547 of 605 for the city of winthrop
Retrieved record 548 of 605 for the city of vardo
Retrieved record 549 of 605 for the city of broome
Retrieved record 550 of 605 for the city of goroka
Retrieved record 551 of 605 for the city of bozoum
Retrieved record 552 of 605 for the city of poso
Retrieved record 553 of 605 for the city of hambantota
Retrieved record 554 of 605 for the city of vila
Retrieved record 555 of 605 for the city of hamilton
Retrieved record 556 of 605 for the city of baruun-urt
Could not retrieve record 557 of 605 for the city of guicheng
Retrieved record 558 of 605 for the city of qui nhon
Retrieved record 559 of 605 for the city of barcelos
Could not retrieve record 560 of 605 for the city of suao
Retrieved record 561 of 605 for the city of soe
Retrieved record 562 of 605 for the city of koksovyy
Could not retrieve record 563 of 605 for the city of ikole
Retrieved record 564 of 605 for the city of fukue
Retrieved record 565 of 605 for the city of mimongo
Could not retrieve record 566 of 605 for the city of warqla
Retrieved record 567 of 605 for the city of homer
Retrieved record 568 of 605 for the city of staryy nadym
Retrieved record 569 of 605 for the city of avera
Retrieved record 570 of 605 for the city of pangnirtung
Retrieved record 571 of 605 for the city of payo
Retrieved record 572 of 605 for the city of road town
Retrieved record 573 of 605 for the city of tanout
Retrieved record 574 of 605 for the city of sigli
Retrieved record 575 of 605 for the city of stephenville
Retrieved record 576 of 605 for the city of flinders
Retrieved record 577 of 605 for the city of abu samrah
Retrieved record 578 of 605 for the city of honggang
Retrieved record 579 of 605 for the city of tautira
Retrieved record 580 of 605 for the city of ust-tsilma
Retrieved record 581 of 605 for the city of olafsvik
Retrieved record 582 of 605 for the city of puerto leguizamo
Retrieved record 583 of 605 for the city of tevriz
Retrieved record 584 of 605 for the city of ancud
Retrieved record 585 of 605 for the city of bocaiuva
Retrieved record 586 of 605 for the city of paita
Retrieved record 587 of 605 for the city of eldorado
Retrieved record 588 of 605 for the city of knin
Retrieved record 589 of 605 for the city of bay city
Retrieved record 590 of 605 for the city of tirunelveli
Retrieved record 591 of 605 for the city of isangel
Retrieved record 592 of 605 for the city of bengkulu
Retrieved record 593 of 605 for the city of kingman
Retrieved record 594 of 605 for the city of vawkavysk
Retrieved record 595 of 605 for the city of nouadhibou
Retrieved record 596 of 605 for the city of boguchany
Retrieved record 597 of 605 for the city of aykhal
Retrieved record 598 of 605 for the city of bubaque
Retrieved record 599 of 605 for the city of izumo
Could not retrieve record 600 of 605 for the city of haibowan
Retrieved record 601 of 605 for the city of mayo
Retrieved record 602 of 605 for the city of college
Retrieved record 603 of 605 for the city of boyuibe
Retrieved record 604 of 605 for the city of praia da vitoria
Retrieved record 605 of 605 for the city of van
Out[7]:
City Approx. Latitude Approx. Longitude Max Temperature (F) Humidity (%) Cloudiness Wind Speed (mph) Actual Latitude Actual Longitude Country Datetime (Local)
0 kloulklubed 3.222335 133.336777 75.2 94 75 9.82 7.04 134.26 PW 07/02/2020, 06:40:32
1 rikitea -54.497065 -112.746685 69.12 69 15 21.74 -23.12 -134.97 PF 07/01/2020, 12:40:32
2 hami 39.870623 91.887579 74.89 20 52 7.7 42.8 93.45 CN 07/02/2020, 05:40:32
3 terrace bay 48.853837 -88.185405 77 53 20 5.82 48.78 -87.1 CA 07/01/2020, 17:40:33
4 saldanha -40.961281 -3.791138 53.6 87 0 3.36 -33.01 17.94 ZA 07/01/2020, 23:40:33

Convert Raw Data to DataFrame

  • Export the city data into a .csv.
  • Display the DataFrame
In [10]:
remaining_cities = city_list.loc[city_list["City"] != "Failed!!!"]
city_left_count = len(remaining_cities)
print("There is data for {} cities out of the {} cities identified, for a retrieval success rate of {:.1%}"
      .format(city_left_count, record_count, (city_left_count/record_count)))

remaining_cities.index = [a for a in range(city_left_count)]


#must change all the columns other than the three below to numeric types - 
#they are currently strings!
non_numeric_cols = ["City", "Country", "Datetime (Local)"]

for col in remaining_cities.columns:
    if(col not in non_numeric_cols):
        remaining_cities[col] = pd.to_numeric(remaining_cities[col])
        
remaining_cities.dtypes
remaining_cities
There is data for 553 cities out of the 605 cities identified, for a retrieval success rate of 91.4%
C:\Users\patri\anaconda3\lib\site-packages\ipykernel_launcher.py:15: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  from ipykernel import kernelapp as app
Out[10]:
City Approx. Latitude Approx. Longitude Max Temperature (F) Humidity (%) Cloudiness Wind Speed (mph) Actual Latitude Actual Longitude Country Datetime (Local)
0 kloulklubed 3.222335 133.336777 75.20 94 75 9.82 7.04 134.26 PW 07/02/2020, 06:40:32
1 rikitea -54.497065 -112.746685 69.12 69 15 21.74 -23.12 -134.97 PF 07/01/2020, 12:40:32
2 hami 39.870623 91.887579 74.89 20 52 7.70 42.80 93.45 CN 07/02/2020, 05:40:32
3 terrace bay 48.853837 -88.185405 77.00 53 20 5.82 48.78 -87.10 CA 07/01/2020, 17:40:33
4 saldanha -40.961281 -3.791138 53.60 87 0 3.36 -33.01 17.94 ZA 07/01/2020, 23:40:33
... ... ... ... ... ... ... ... ... ... ... ...
548 mayo 66.278308 -138.618830 78.80 78 75 6.93 38.89 -76.51 US 07/01/2020, 17:42:35
549 college 76.774835 -145.972672 62.01 38 75 3.36 64.86 -147.80 US 07/01/2020, 13:41:32
550 boyuibe -20.328386 -62.402946 55.26 39 0 3.94 -20.42 -63.28 BO 07/01/2020, 17:42:36
551 praia da vitoria 44.480781 -22.654227 68.00 72 40 5.14 38.73 -27.07 PT 07/01/2020, 21:42:36
552 van 38.437716 43.987713 62.60 55 75 10.29 38.49 43.38 TR 07/02/2020, 00:42:36

553 rows × 11 columns

In [ ]:
 

Inspect the data and remove the cities where the humidity > 100%.


Skip this step if there are no cities that have humidity > 100%.

In [11]:
#check if there are any cities with >100% humidity
test_stats = remaining_cities["Humidity (%)"].describe(include = "all")
print("By inspection, the maximum humidity value is 100%, so there are no values greater than 100% in our data!")
test_stats

# remaining_cities["Humidity (%)"].value_counts()
By inspection, the maximum humidity value is 100%, so there are no values greater than 100% in our data!
Out[11]:
count    553.000000
mean      70.084991
std       20.958162
min        3.000000
25%       58.000000
50%       75.000000
75%       85.000000
max      100.000000
Name: Humidity (%), dtype: float64
In [12]:
#  Get the indices of cities that have humidity over 100%.
In [13]:
# Make a new DataFrame equal to the city data to drop all humidity outliers by index.
# Passing "inplace=False" will make a copy of the city_data DataFrame, which we call "clean_city_data".
In [14]:
# Extract relevant fields from the data frame


# Export the City_Data into a csv
remaining_cities.to_csv("../output_data/Retrieved_City_Weather_Data.csv")
remaining_cities
Out[14]:
City Approx. Latitude Approx. Longitude Max Temperature (F) Humidity (%) Cloudiness Wind Speed (mph) Actual Latitude Actual Longitude Country Datetime (Local)
0 kloulklubed 3.222335 133.336777 75.20 94 75 9.82 7.04 134.26 PW 07/02/2020, 06:40:32
1 rikitea -54.497065 -112.746685 69.12 69 15 21.74 -23.12 -134.97 PF 07/01/2020, 12:40:32
2 hami 39.870623 91.887579 74.89 20 52 7.70 42.80 93.45 CN 07/02/2020, 05:40:32
3 terrace bay 48.853837 -88.185405 77.00 53 20 5.82 48.78 -87.10 CA 07/01/2020, 17:40:33
4 saldanha -40.961281 -3.791138 53.60 87 0 3.36 -33.01 17.94 ZA 07/01/2020, 23:40:33
... ... ... ... ... ... ... ... ... ... ... ...
548 mayo 66.278308 -138.618830 78.80 78 75 6.93 38.89 -76.51 US 07/01/2020, 17:42:35
549 college 76.774835 -145.972672 62.01 38 75 3.36 64.86 -147.80 US 07/01/2020, 13:41:32
550 boyuibe -20.328386 -62.402946 55.26 39 0 3.94 -20.42 -63.28 BO 07/01/2020, 17:42:36
551 praia da vitoria 44.480781 -22.654227 68.00 72 40 5.14 38.73 -27.07 PT 07/01/2020, 21:42:36
552 van 38.437716 43.987713 62.60 55 75 10.29 38.49 43.38 TR 07/02/2020, 00:42:36

553 rows × 11 columns

Plotting the Data

  • Use proper labeling of the plots using plot titles (including date of analysis) and axes labels.
  • Save the plotted figures as .pngs.

Latitude vs. Temperature Plot

In [15]:
lat_vs_T_axes = remaining_cities.plot(kind="scatter", x="Actual Latitude", y="Max Temperature (F)", 
                                      title="Maximum Temperature (F) vs. City Latitude")

lat_vs_T_axes.get_figure().savefig("../output_data/Temp_vs_Latitude_All_Cities.png")

The Temperature (F) vs. Latitude plot shown above, which includes data from all cities, peaks at approximately 20-degrees latitude. The latitude values below that latitude show a possible linear relationship with temperature, and the latitude values above that latitude also show a possible linear relationship with temperature, with both trends ending at the same peak temperature and latitude.

Latitude vs. Humidity Plot

In [16]:
lat_vs_humidity_axes = remaining_cities.plot(kind="scatter", x="Actual Latitude", y="Humidity (%)", 
                                      title="Humidity (%) vs. City Latitude")

lat_vs_humidity_axes.get_figure().savefig("../output_data/Humidity_vs_Latitude_All_Cities.png")

The Humidity vs. Latitude plot shown above, which contains data from all cities, shows a relatively spread-out distribution of data points. There does not appear to be a relationship between humidity and latitude at first glance, but the humidity percentages seem to largely cluster above 50%.

Latitude vs. Cloudiness Plot

In [17]:
lat_vs_cloudiness_axes = remaining_cities.plot(kind="scatter", x="Actual Latitude", y="Cloudiness", 
                                      title="Cloudiness vs. City Latitude")

lat_vs_cloudiness_axes.get_figure().savefig("../output_data/Cloudiness_vs_Latitude_All_Cities.png")

The Cloudiness vs. Latitude plot shown above, containing data from all cities, does not seem to show a relationship between cloudiness and city latitude. There seem to be some values for cloudiness that the points cluster along, noticeably 0, 20, 40, 75, 90, and 100, so those values may be rounded or categorized from some of the sources, and not represent continuous variables or measurements.

Latitude vs. Wind Speed Plot

In [18]:
lat_vs_wind_speed_axes = remaining_cities.plot(kind="scatter", x="Actual Latitude", y="Wind Speed (mph)", 
                                      title="Wind Speed (mph) vs. City Latitude")

lat_vs_wind_speed_axes.get_figure().savefig("../output_data/Wind_Speed_vs_Latitude_All_Cities.png")

The Wind speed vs. Latitude plot, shown above for all cities, does not seem to show any relationship between wind speed and latitude. Most of the wind speed values are below about 25 mph, with only a few values above that wind speed limit.

Linear Regression

In [19]:
# OPTIONAL: Create a function to create Linear Regression plots

#takes in as arguments a DataFrame (df), the x-axis String column name (x_Col), and the y-axis String column name (y_Col)
#plots a scatter plot with the df[x_Col] on the x-axis and the df[y_Col] data on the y-axis, and the linear regression line
#prints information about the best fit line from the linear regression
#returns the axes object for the plot, so more changes can be made later if necessary
def makeLinRegression(df, x_Col, y_Col):
    #first, perform the linear regression on the data
    (regr_slope, regr_intercept, regr_r_val, _, _) = linregress(df[x_Col], 
                                                           df[y_Col])
    #setup the linear regression line x and y axes data points
    regr_line_x = np.array([a for a in range(int(min(df[x_Col].values)), int(max(df[x_Col].values)+1))])
    regr_line_y = regr_slope * regr_line_x + regr_intercept

    #plot the scatterplot with the raw data first!
    df_axes = df.plot(kind="scatter", x=x_Col, y=y_Col, 
                      title="{} vs. {} ({})"
                        .format(y_Col, x_Col, remaining_cities["Datetime (Local)"].iloc[0].split(",")[0]))

    #add the best fit lines to the plot as a solid red line
    df_axes.plot(regr_line_x, regr_line_y, 'r')

    #output best-fit line information
    print("The equation of the best-fit linear regression line for this chart is y={:.2f}x+{:.2f}"
          .format(regr_slope, regr_intercept))
    print("The r-squared correlation coefficient for this line is {:.2f}".format(regr_r_val))
                  
    #return the axes object for the plots, in case any changes need to be made
    return df_axes
In [20]:
# Create Northern and Southern Hemisphere DataFrames

#first, get a subset of all the cities that are on or north of the equator for the Northern Hemisphere DataFrame
northern_hemisphere = remaining_cities.loc[remaining_cities["Actual Latitude"] >= 0]
northern_cities_count = len(northern_hemisphere)
print("There are {} cities in the northern hemisphere out of {} cities total, representing {:.1%} of all cities in the data set."
     .format(northern_cities_count, city_left_count, (northern_cities_count/city_left_count)))

#first, get a subset of all the cities that are south of the equator for the Southern Hemisphere DataFrame
southern_hemisphere = remaining_cities.loc[remaining_cities["Actual Latitude"] < 0]
southern_cities_count = len(southern_hemisphere)
print("There are {} cities in the southern hemisphere out of {} cities total, representing {:.1%} of all cities in the data set."
     .format(southern_cities_count, city_left_count, (southern_cities_count/city_left_count)))
There are 388 cities in the northern hemisphere out of 553 cities total, representing 70.2% of all cities in the data set.
There are 165 cities in the southern hemisphere out of 553 cities total, representing 29.8% of all cities in the data set.

Northern Hemisphere - Max Temp vs. Latitude Linear Regression

In [21]:
(n_temp_slope, n_temp_intercept, n_temp_r_val, _, _) = linregress(northern_hemisphere["Actual Latitude"], 
                                                           northern_hemisphere["Max Temperature (F)"])

regr_line_x = np.array([a for a in range(80)])
regr_line_y = n_temp_slope * regr_line_x + n_temp_intercept

n_temp_axes = northern_hemisphere.plot(kind="scatter", x="Actual Latitude", 
                                       y="Max Temperature (F)", 
                                       title="Max Temperature (F) vs. Actual Latitude ({})".
                                       format(remaining_cities["Datetime (Local)"].iloc[0].split(",")[0]))
                        

n_temp_axes.plot(regr_line_x, regr_line_y, 'r')

print("The equation of the best-fit linear regression line for this chart is y={:.2f}x+{:.2f}"
      .format(n_temp_slope, n_temp_intercept))
print("The r-squared correlation coefficient for this line is {:.2f}".format(n_temp_r_val))
n_temp_axes.get_figure().savefig("../output_data/Temp_vs_Latitude_N_Hemisphere.png")
The equation of the best-fit linear regression line for this chart is y=-0.52x+90.49
The r-squared correlation coefficient for this line is -0.72

The Max Temperature vs. Latitude plot for cities in the northern hemisphere is shown above. The max temperature appears show a strong negative linear relationship with latitudes in the northern hemisphere, with an r-value of -0.72 for the linear best-fit regression line.

Southern Hemisphere - Max Temp vs. Latitude Linear Regression

In [22]:
s_temp_lat_axes = makeLinRegression(southern_hemisphere, "Actual Latitude", "Max Temperature (F)")
s_temp_lat_axes.get_figure().savefig("../output_data/Temp_vs_Latitude_S_Hemisphere.png")
The equation of the best-fit linear regression line for this chart is y=0.83x+81.01
The r-squared correlation coefficient for this line is 0.84

The Max Temperature vs. Latitude plot for cities in the southern hemisphere is shown above. The max temperature appears show a strong positive linear relationship with latitudes in the southern hemisphere, with an r-value of 0.84 for the linear best-fit regression line.

Northern Hemisphere - Humidity (%) vs. Latitude Linear Regression

In [23]:
n_humidity_lat_axes = makeLinRegression(northern_hemisphere, "Actual Latitude", "Humidity (%)")
n_humidity_lat_axes.get_figure().savefig("../output_data/Humidity_vs_Latitude_N_Hemisphere.png")
The equation of the best-fit linear regression line for this chart is y=0.03x+66.74
The r-squared correlation coefficient for this line is 0.03

The Humidity vs. Latitude plot for cities in the northern hemisphere is shown above. The data seems to show no relationship between the humidity and latitude for the northern hemisphere.

Southern Hemisphere - Humidity (%) vs. Latitude Linear Regression

In [24]:
s_humidity_lat_axes = makeLinRegression(southern_hemisphere, "Actual Latitude", "Humidity (%)")
s_humidity_lat_axes.get_figure().savefig("../output_data/Humidity_vs_Latitude_S_Hemisphere.png")
The equation of the best-fit linear regression line for this chart is y=-0.06x+73.82
The r-squared correlation coefficient for this line is -0.05

The Humidity vs. Latitude plot for cities in the southern hemisphere is shown above. The data seems to show no relationship between the humidity and latitude for the southern hemisphere.

Northern Hemisphere - Cloudiness (%) vs. Latitude Linear Regression

In [25]:
n_cloudiness_lat_axes = makeLinRegression(northern_hemisphere, "Actual Latitude", "Cloudiness")
n_cloudiness_lat_axes.get_figure().savefig("../output_data/Cloudiness_vs_Latitude_N_Hemisphere.png")
The equation of the best-fit linear regression line for this chart is y=-0.14x+54.04
The r-squared correlation coefficient for this line is -0.08

The Cloudiness vs. Latitude plot for cities in the northern hemisphere is shown above. The data seems to show no relationship between cloudiness and latitude for the northern hemisphere.

Southern Hemisphere - Cloudiness (%) vs. Latitude Linear Regression

In [27]:
s_cloudiness_lat_axes = makeLinRegression(southern_hemisphere, "Actual Latitude", "Cloudiness")
s_cloudiness_lat_axes.get_figure().savefig("../output_data/Cloudiness_vs_Latitude_S_Hemisphere.png")
The equation of the best-fit linear regression line for this chart is y=-0.00x+38.82
The r-squared correlation coefficient for this line is -0.00

The Cloudiness vs. Latitude plot for cities in the southern hemisphere is shown above. The data seems to show no relationship between cloudiness and latitude for the southern hemisphere.

Northern Hemisphere - Wind Speed (mph) vs. Latitude Linear Regression

In [28]:
n_wind_lat_axes = makeLinRegression(northern_hemisphere, "Actual Latitude", "Wind Speed (mph)")
n_wind_lat_axes.get_figure().savefig("../output_data/Wind_Speed_vs_Latitude_N_Hemisphere.png")
The equation of the best-fit linear regression line for this chart is y=0.01x+7.61
The r-squared correlation coefficient for this line is 0.04

The Wind Speed vs. Latitude plot for cities in the northern hemisphere is shown above. The data seems to show no relationship between wind speed and latitude for the northern hemisphere.

Southern Hemisphere - Wind Speed (mph) vs. Latitude Linear Regression

In [29]:
s_wind_lat_axes=makeLinRegression(southern_hemisphere, "Actual Latitude", "Wind Speed (mph)")
s_wind_lat_axes.get_figure().savefig("../output_data/Wind_Speed_vs_Latitude_S_Hemisphere.png")
The equation of the best-fit linear regression line for this chart is y=0.03x+7.67
The r-squared correlation coefficient for this line is 0.08

The Wind Speed vs. Latitude plot for cities in the southern hemisphere is shown above. The data seems to show no relationship between wind speed and latitude for the southern hemisphere.

In [ ]: