<jupyter_start><jupyter_text>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.  Observable Trends1.) As displayed in the City Latitude vs Max Temperature plot, you can see that as you travel away from the equator the temperature decreases. This is magnified when looking at the latitude vs temperature in the northern hemisphere. There is a strong negative relationship, with an r coefficient value of -0.89, meaning the temperature decreases as you travel farther north.2.) There is no observable correlation between latitude and wind speed for either of the hemispheres. This is demonstrated by the very weak r values of -.06 and -.12.3.) A weak to moderate relationship can be seen between latitude and humidity, with r values of .39 in the northern hemisphere and .44 in the south.4.) Even though the data displays weak to no relationship between latitude and humidity, cloudiness, and wind speed, this is only a representation of weather across the world in a single day. We could gain further insight by viewing weather patterns over a longer period of time.<jupyter_code># 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 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)<jupyter_output><empty_output><jupyter_text>Generate Cities List<jupyter_code># 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)

# 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
    if city not in cities:
        cities.append(city)
        
# Print the city count to confirm sufficient count
total = len(cities)
print(f"We have found a total of {total} cities.")<jupyter_output>We have found a total of 614 cities.<jupyter_text>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).<jupyter_code># create empty lists for location info & weather variables
found_cities = []
country = []
lat = []
lng = []
max_temp = []
humid = []
clouds = []
wind_speed = []
date = []
# loop through cities list to build out json response and print log
url = f"http://api.openweathermap.org/data/2.5/weather?appid={weather_api_key}&units=imperial&q="

print("Beginning Data Retrieval     ")
print("-----------------------------")

for index, city in enumerate(cities):
    try:
        query = f"{url}{city}"
        response = requests.get(query)
        result = response.json()
        
    # append city & weather variable data to lists
        country.append(result["sys"]["country"])
        lat.append(result["coord"]["lat"])
        lng.append(result["coord"]["lon"])
        max_temp.append(result["main"]["temp_max"])
        humid.append(result["main"]["humidity"])
        clouds.append(result["clouds"]["all"])
        wind_speed.append(result["wind"]["speed"])
        date.append(result["dt"])
        
    # increase index and print process statement
        index += 1
        print(f"Processing Record #{index} | {city}")
        
        found_cities.append(city)
        
    except:
        index += 1
        print(f"Record #{index} not found. Skipping...")

print("-----------------------------")
print("Data Retrieval Complete      ")
print("-----------------------------")<jupyter_output>Beginning Data Retrieval     
-----------------------------
Processing Record #1 | rikitea
Processing Record #2 | qaanaaq
Processing Record #3 | anadyr
Record #4 not found. Skipping...
Processing Record #5 | yellowknife
Processing Record #6 | hasaki
Processing Record #7 | punta arenas
Record #8 not found. Skipping...
Processing Record #9 | bredasdorp
Processing Record #10 | hithadhoo
Record #11 not found. Skipping...
Processing Record #12 | luderitz
Processing Record #13 | xichang
Processing Record #14 | portland
Processing Record #15 | albany
Processing Record #16 | mount isa
Processing Record #17 | atuona
Processing Record #18 | barrow
Processing Record #19 | edea
Processing Record #20 | burnie
Processing Record #21 | nikolskoye
Processing Record #22 | ambilobe
Processing Record #23 | busselton
Record #24 not found. Skipping...
Processing Record #25 | bilibino
Processing Record #26 | hilo
Processing Record #27 | hermanus
Processing Record #28 | montevideo
Processing Record #29 | acap[...]<jupyter_text>Convert Raw Data to DataFrame* Export the city data into a .csv.* Display the DataFrame<jupyter_code># create dataframe
weather_df = pd.DataFrame({
    "City": found_cities,
    "Country": country,
    "Latitude": lat,
    "Longitude": lng,
    "Max Temp (F)": max_temp,
    "Humidity (%)": humid,
    "Cloudiness (%)": clouds,
    "Wind Speed (mph)": wind_speed,
    "Date": date
})

weather_df
# export to csv
csv_path = "../output_data/weather.csv"
weather_csv = weather_df.to_csv(csv_path, index=False)
weather_df.count()
weather_df.describe()<jupyter_output><empty_output><jupyter_text>Inspect the data and remove the cities where the humidity > 100%.----Skip this step if there are no cities that have humidity > 100%.<jupyter_code>#  Get the indices of cities that have humidity over 100%.
humid_df = weather_df.loc[weather_df["Humidity (%)"] > 100].index
humid_df
# 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".
city_df = weather_df.drop(humid_df, inplace=False)

city_path = "../output_data/cities.csv"
cities_csv = city_df.to_csv(city_path, index=False)

# wasn't actually necessary, humidity cannot exceed 100% - that is called rain.<jupyter_output><empty_output><jupyter_text>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<jupyter_code>plt.scatter(city_df["Latitude"], city_df["Max Temp (F)"])
plt.ylabel("Max Temperature (F)", fontweight="bold")
plt.xlabel("Latitude", fontweight="bold")
plt.title("City Latitude vs. Temperature (%s)" % time.strftime("%x"), fontweight="bold")
plt.grid(True)
plt.savefig("../output_data/lat_vs_temp.png")
plt.show()

# strftime documentation: https://www.programiz.com/python-programming/datetime/strftime<jupyter_output><empty_output><jupyter_text>The above plot analyzes the relationship between a city's latitude and the max temperature on February 16, 2021. It shows that as you travel away from the equator, the temperature decreases.  Latitude vs. Humidity Plot<jupyter_code>plt.scatter(city_df["Latitude"], city_df["Humidity (%)"])
plt.ylabel("Humidity (%)", fontweight="bold")
plt.xlabel("Latitude", fontweight="bold")
plt.title("City Latitude vs. Humidity (%s)" % time.strftime("%x"), fontweight="bold")
plt.grid(True)
plt.savefig("../output_data/lat_vs_humidity.png")
plt.show()<jupyter_output><empty_output><jupyter_text>The above plot analyzes the relationship between a city's latitude and the humidity on February 16, 2021. No clear correlation is shown between latitude and humidity.  Latitude vs. Cloudiness Plot<jupyter_code>plt.scatter(city_df["Latitude"], city_df["Cloudiness (%)"])
plt.ylabel("Cloudiness (%)", fontweight="bold")
plt.xlabel("Latitude", fontweight="bold")
plt.title("City Latitude vs. Cloudiness (%s)" % time.strftime("%x"), fontweight="bold")
plt.grid(True)
plt.savefig("../output_data/lat_vs_clouds.png")
plt.show()<jupyter_output><empty_output><jupyter_text>The above plot analyzes the relationship between a city's latitude and cloudiness on February 16, 2021. There does not seem to be any correlation between latitude and cloudiness.  Latitude vs. Wind Speed Plot<jupyter_code>plt.scatter(city_df["Latitude"], city_df["Wind Speed (mph)"])
plt.ylabel("Wind Speed (mph)", fontweight="bold")
plt.xlabel("Latitude", fontweight="bold")
plt.title("City Latitude vs. Wind Speed (%s)" % time.strftime("%x"), fontweight="bold")
plt.grid(True)
plt.savefig("../output_data/lat_vs_wind.png")
plt.show()<jupyter_output><empty_output><jupyter_text>The above plot analyzes the relationship between a city's latitude and wind speed on February 16, 2021. Again, the data does not display any clear correlation between latitude and wind speed.  Linear Regression<jupyter_code># create northern & southern city dataframes

north_df = city_df.loc[weather_df["Latitude"] > 0]
south_df = city_df.loc[weather_df["Latitude"] < 0]<jupyter_output><empty_output><jupyter_text>Northern Hemisphere - Max Temp vs. Latitude Linear Regression<jupyter_code># linear reg calculations
(slope, intercept, rvalue, pvalue, stderr) = linregress(north_df["Latitude"], north_df["Max Temp (F)"])
slope = round(slope, 2)
intercept = round(intercept, 2)
rvalue = round(rvalue, 2)
regress_values = (slope * north_df["Latitude"]) + intercept
line_eq = f"y = {slope}x + {intercept}"

# print r value statement
print(f"The correlation coefficient between the Northern Hemisphere Max Temp vs. Latitude is r = {rvalue}")

# plot, label, and annotate
# plt.figure(figsize = (10,8))
plt.scatter(north_df["Latitude"], north_df["Max Temp (F)"])
plt.xlabel("Latitude")
plt.ylabel("Max Temp (F)")
plt.title("Northern Hemisphere Max Temp vs. Latitude (%s)" % time.strftime("%x"))

plt.plot(north_df["Latitude"], regress_values, "r-")
plt.annotate(line_eq, (10,-20), fontsize=14, color="red")
plt.savefig("../output_data/north_hem_vs_maxtemp.png")
plt.show()<jupyter_output>The correlation coefficient between the Northern Hemisphere Max Temp vs. Latitude is r = -0.89<jupyter_text>Southern Hemisphere - Max Temp vs. Latitude Linear Regression<jupyter_code># linear regr calculations
(slope, intercept, rvalue, pvalue, stderr) = linregress(south_df["Latitude"], south_df["Max Temp (F)"])
slope = round(slope, 2)
intercept = round(intercept, 2)
rvalue = round(rvalue, 2)
regress_values = (slope * south_df["Latitude"]) + intercept
line_eq = f"y = {slope}x + {intercept}"

# print r value statement
print(f"The correlation coefficient between the Southern Hemisphere Max Temp vs. Latitude is r = {rvalue}")

# plot, label, and annotate
plt.scatter(south_df["Latitude"], south_df["Max Temp (F)"])
plt.xlabel("Latitude")
plt.ylabel("Max Temp (F)")
plt.title("Southern Hemisphere Max Temp vs. Latitude (%s)" % time.strftime("%x"))

plt.plot(south_df["Latitude"], regress_values, "r-")
plt.annotate(line_eq, (-25,52), fontsize=14, color="red")
plt.savefig("../output_data/south_hem_vs_maxtemp.png")
plt.show()<jupyter_output>The correlation coefficient between the Southern Hemisphere Max Temp vs. Latitude is r = 0.46<jupyter_text>Northern Hemisphere - Humidity (%) vs. Latitude Linear Regression<jupyter_code># linear reg calculations
(slope, intercept, rvalue, pvalue, stderr) = linregress(north_df["Latitude"], north_df["Humidity (%)"])
slope = round(slope, 2)
intercept = round(intercept, 2)
rvalue = round(rvalue, 2)
regress_values = (slope * north_df["Latitude"]) + intercept
line_eq = f"y = {slope}x + {intercept}"

# print r value statement
print(f"The correlation coefficient between the Northern Hemisphere Humidity (%) vs. Latitude is r = {rvalue}")

# plot, label, and annotate
# plt.figure(figsize = (10,8))
plt.scatter(north_df["Latitude"], north_df["Humidity (%)"])
plt.xlabel("Latitude")
plt.ylabel("Humidity (%)")
plt.title("Northern Hemisphere Humidity vs. Latitude (%s)" % time.strftime("%x"))

plt.plot(north_df["Latitude"], regress_values, "r-")
plt.annotate(line_eq, (40,20), fontsize=14, color="red")
plt.savefig("../output_data/north_hem_vs_humidity.png")
plt.show()<jupyter_output>The correlation coefficient between the Northern Hemisphere Humidity (%) vs. Latitude is r = 0.39<jupyter_text>Southern Hemisphere - Humidity (%) vs. Latitude Linear Regression<jupyter_code># linear regr calculations
(slope, intercept, rvalue, pvalue, stderr) = linregress(south_df["Latitude"], south_df["Humidity (%)"])
slope = round(slope, 2)
intercept = round(intercept, 2)
rvalue = round(rvalue, 2)
regress_values = (slope * south_df["Latitude"]) + intercept
line_eq = f"y = {slope}x + {intercept}"

# print r value statement
print(f"The correlation coefficient between the Southern Hemisphere Humidity (%) vs. Latitude is r = {rvalue}")

# plot, label, and annotate
plt.scatter(south_df["Latitude"], south_df["Humidity (%)"])
plt.xlabel("Latitude")
plt.ylabel("Humidity (%)")
plt.title("Southern Hemisphere Humidity vs. Latitude (%s)" % time.strftime("%x"))

plt.plot(south_df["Latitude"], regress_values, "r-")
plt.annotate(line_eq, (-22,30), fontsize=14, color="red")
plt.savefig("../output_data/south_hem_vs_humidity.png")
plt.show()<jupyter_output>The correlation coefficient between the Southern Hemisphere Humidity (%) vs. Latitude is r = 0.44<jupyter_text>Northern Hemisphere - Cloudiness (%) vs. Latitude Linear Regression<jupyter_code># linear reg calculations
(slope, intercept, rvalue, pvalue, stderr) = linregress(north_df["Latitude"], north_df["Cloudiness (%)"])
slope = round(slope, 2)
intercept = round(intercept, 2)
rvalue = round(rvalue, 2)
regress_values = (slope * north_df["Latitude"]) + intercept
line_eq = f"y = {slope}x + {intercept}"

# print r value statement
print(f"The correlation coefficient between the Northern Hemisphere Cloudiness (%) vs. Latitude is r = {rvalue}")

# plot, label, and annotate
# plt.figure(figsize = (10,8))
plt.scatter(north_df["Latitude"], north_df["Cloudiness (%)"])
plt.xlabel("Latitude")
plt.ylabel("Cloudiness (%)")
plt.title("Northern Hemisphere Cloudiness vs. Latitude (%s)" % time.strftime("%x"))

plt.plot(north_df["Latitude"], regress_values, "r-")
plt.annotate(line_eq, (43,31), fontsize=14, color="red")
plt.savefig("../output_data/north_hem_vs_clouds.png")
plt.show()<jupyter_output>The correlation coefficient between the Northern Hemisphere Cloudiness (%) vs. Latitude is r = 0.14<jupyter_text>Southern Hemisphere - Cloudiness (%) vs. Latitude Linear Regression<jupyter_code># linear regr calculations
(slope, intercept, rvalue, pvalue, stderr) = linregress(south_df["Latitude"], south_df["Cloudiness (%)"])
slope = round(slope, 2)
intercept = round(intercept, 2)
rvalue = round(rvalue, 2)
regress_values = (slope * south_df["Latitude"]) + intercept
line_eq = f"y = {slope}x + {intercept}"

# print r value statement
print(f"The correlation coefficient between the Southern Hemisphere Cloudiness (%) vs. Latitude is r = {rvalue}")

# plot, label, and annotate
plt.scatter(south_df["Latitude"], south_df["Cloudiness (%)"])
plt.xlabel("Latitude")
plt.ylabel("Cloudiness (%)")
plt.title("Southern Hemisphere Cloudiness vs. Latitude (%s)" % time.strftime("%x"))

plt.plot(south_df["Latitude"], regress_values, "r-")
plt.annotate(line_eq, (-50,57), fontsize=14, color="red")
plt.savefig("../output_data/south_hem_vs_clouds.png")
plt.show()<jupyter_output>The correlation coefficient between the Southern Hemisphere Cloudiness (%) vs. Latitude is r = 0.51<jupyter_text>Northern Hemisphere - Wind Speed (mph) vs. Latitude Linear Regression<jupyter_code># linear reg calculations
(slope, intercept, rvalue, pvalue, stderr) = linregress(north_df["Latitude"], north_df["Wind Speed (mph)"])
slope = round(slope, 2)
intercept = round(intercept, 2)
rvalue = round(rvalue, 2)
regress_values = (slope * north_df["Latitude"]) + intercept
line_eq = f"y = {slope}x + {intercept}"

# print r value statement
print(f"The correlation coefficient between the Northern Hemisphere Wind Speed (mph) vs. Latitude is r = {rvalue}")

# plot, label, and annotate
# plt.figure(figsize = (10,8))
plt.scatter(north_df["Latitude"], north_df["Wind Speed (mph)"])
plt.xlabel("Latitude")
plt.ylabel("Wind Speed (mph)")
plt.title("Northern Hemisphere Wind Speed vs. Latitude (%s)" % time.strftime("%x"))

plt.plot(north_df["Latitude"], regress_values, "r-")
plt.annotate(line_eq, (40,28), fontsize=14, color="red")
plt.savefig("../output_data/north_hem_vs_wind.png")
plt.show()<jupyter_output>The correlation coefficient between the Northern Hemisphere Wind Speed (mph) vs. Latitude is r = -0.06<jupyter_text>Southern Hemisphere - Wind Speed (mph) vs. Latitude Linear Regression<jupyter_code># linear regr calculations
(slope, intercept, rvalue, pvalue, stderr) = linregress(south_df["Latitude"], south_df["Wind Speed (mph)"])
slope = round(slope, 2)
intercept = round(intercept, 2)
rvalue = round(rvalue, 2)
regress_values = (slope * south_df["Latitude"]) + intercept
line_eq = f"y = {slope}x + {intercept}"

# print r value statement
print(f"The correlation coefficient between the Southern Hemisphere Wind Speed (mph) vs. Latitude is r = {rvalue}")

# plot, label, and annotate
plt.scatter(south_df["Latitude"], south_df["Wind Speed (mph)"])
plt.xlabel("Latitude")
plt.ylabel("Wind Speed (mph)")
plt.title("Southern Hemisphere Wind Speed vs. Latitude (%s)" % time.strftime("%x"))

plt.plot(south_df["Latitude"], regress_values, "r-")
plt.annotate(line_eq, (-50,18), fontsize=14, color="red")
plt.savefig("../output_data/south_hem_vs_wind.png")
plt.show()<jupyter_output>The correlation coefficient between the Southern Hemisphere Wind Speed (mph) vs. Latitude is r = -0.12
{'fraction_non_alphanumeric': 0.13641722337618592, 'fraction_numerical': 0.013697861112670521, 'mean_word_length': 5.41945945945946, 'pattern_counts': {'":': 9, '<': 64, '<?xml version=': 0, '>': 67, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '18', 'dir': 'jupyter-structured-clean-dedup', 'id': '497411', 'license': 'ADSL', 'n_tokens_mistral': 6138, 'n_tokens_neox': 5667, 'n_words': 1700, 'path': 'WeatherPy/WeatherPy.ipynb', 'repo_name': 'catielutz/Python-API-Challenge', 'size': '17813'}