<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.<jupyter_code># Dependencies and Setup
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import requests
import time
import scipy.stats as st
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
len(cities)<jupyter_output><empty_output><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># Save config information.
url = "http://api.openweathermap.org/data/2.5/weather?"
units = "imperial"

# Build partial query URL
base_url = f"{url}appid={weather_api_key}&units={units}&q="
base_url
query_url = base_url + city
query_url
response = requests.get(base_url).json()
# List of City data
lat = []
lon = []
temp = []
humidity = [] 
cloudy = []
windspee = []
count = 0
cityname = []
dt = []
# Get weather data
print("Beginning Data Retrival")
print("-----------------------------")
set_count = 1
record_count = 1
weather_data = {"City":[],"Lat":[],"Lng":[],"Max Temp":[],"Humidity":[],"Cloudiness":[],"Wind Speed": [],"Country":[],"Date":[]}
for city in cities:
    weather_response = requests.get(base_url + city)
    weather_response_json = weather_response.json()
    
    if weather_response.status_code == 200:
        weather_data["City"].append(city)
        weather_data["Lat"].append(weather_response_json['coord']['lat'])
        weather_data["Lng"].append(weather_response_json['coord']['lon'])
        weather_data["Max Temp"].append(weather_response_json['main']['temp_max'])
        weather_data["Humidity"].append(weather_response_json['main']['humidity'])
        weather_data["Cloudiness"].append(weather_response_json['clouds']['all'])
        weather_data["Wind Speed"].append(weather_response_json['wind']['speed'])
        weather_data["Country"].append(weather_response_json['sys']['country'])
        weather_data["Date"].append(weather_response_json['dt'])
        if record_count <= 50:
            print(f"Processing Record {record_count} of Set {set_count} | {city}")
            record_count += 1 
        else:
            record_count = 0
            set_count += 1
            print(f"Processing Record {record_count} of Set {set_count} | {city}")
            record_count += 1
    else:
        print("City not found. Skipping...")
print("-----------------------------")
print("Data Retrieval Complete")
print("-----------------------------")<jupyter_output>Beginning Data Retrival
-----------------------------
Processing Record 1 of Set 1 | <NAME>
Processing Record 2 of Set 1 | <NAME>
Processing Record 3 of Set 1 | vaini
Processing Record 4 of Set 1 | upernavik
Processing Record 5 of Set 1 | busselton
Processing Record 6 of Set 1 | ghosi
Processing Record 7 of Set 1 | mataura
Processing Record 8 of Set 1 | pevek
Processing Record 9 of Set 1 | labuhan
Processing Record 10 of Set 1 | poum
Processing Record 11 of Set 1 | ushuaia
Processing Record 12 of Set 1 | gat
Processing Record 13 of Set 1 | saint george
Processing Record 14 of Set 1 | saint-philippe
City not found. Skipping...
Processing Record 15 of Set 1 | punta arenas
Processing Record 16 of Set 1 | carnarvon
City not found. Skipping...
Processing Record 17 of Set 1 | yellowknife
Processing Record 18 of Set 1 | albany
Processing Record 19 of Set 1 | bluff
Processing Record 20 of Set 1 | hasaki
Processing Record 21 of Set 1 | ilulissat
Processing Record 22 of Set 1 | kalemie
P[...]<jupyter_text>Convert Raw Data to DataFrame* Export the city data into a .csv.* Display the DataFrame<jupyter_code>weather_df = pd.DataFrame(weather_data)
weather_df.head()
weather_df.count()
# Export data to csv
weather_df.to_csv('weather_data.csv', index=False)<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>weather_df.describe()
#  No Cities with Humidity >100%<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># Scatter plot
plt.scatter(weather_df["Lat"],weather_df["Max Temp"], edgecolor="black")

# Labels
plt.title("City Latitude vs. Max Temperature (06/18/20)")
plt.xlabel("Latitude")
plt.ylabel("Max Temperature (F)")
plt.grid(True)

# Save as PNG and Show
plt.savefig("LatVTemp.png")
plt.show()<jupyter_output><empty_output><jupyter_text>Latitude vs. Humidity Plot<jupyter_code># Scatter plot
plt.scatter(weather_df["Lat"],weather_df["Humidity"], edgecolor="black")

# Labels
plt.title("City Latitude vs. Humidity (06/18/20)")
plt.xlabel("Latitude")
plt.ylabel("Humidity (%)")
plt.grid(True)

# Save as PNG and Show
plt.savefig("LatVHumidity.png")
plt.show()<jupyter_output><empty_output><jupyter_text>Latitude vs. Cloudiness Plot<jupyter_code># Scatter plot
plt.scatter(weather_df["Lat"],weather_df["Cloudiness"], edgecolor="black")

# Labels
plt.title("City Latitude vs. Cloudiness (06/18/20)")
plt.xlabel("Latitude")
plt.ylabel("Cloudiness (%)")
plt.grid(True)

# Save as PNG and Show
plt.savefig("LatVCloud.png")
plt.show()<jupyter_output><empty_output><jupyter_text>Latitude vs. Wind Speed Plot<jupyter_code># Scatter plot
plt.scatter(weather_df["Lat"],weather_df["Wind Speed"], edgecolor="black")

# Labels
plt.title("City Latitude vs. Wind Speed (08/22/18)")
plt.xlabel("Latitude")
plt.ylabel("Wind Speed (mph)")
plt.grid(True)

# Save as PNG and Show
plt.savefig("LatVWindSpeed.png")
plt.show()<jupyter_output><empty_output><jupyter_text>Linear Regression<jupyter_code># OPTIONAL: Create a function to create Linear Regression plots
# Create Northern and Southern Hemisphere DataFrames
n_hemisphere = weather_df.loc[weather_df["Lat"] >= 0]
s_hemisphere = weather_df.loc[weather_df["Lat"] < 0]
n_hemisphere.head()
n_hemisphere.describe()
s_hemisphere.head()
s_hemisphere.describe()<jupyter_output><empty_output><jupyter_text>Northern Hemisphere - Max Temp vs. Latitude Linear Regression<jupyter_code># Calculate the correlation coefficient and linear regression model 
(slope, intercept,rvalue, pvalue, stderr) = linregress(n_hemisphere["Lat"], n_hemisphere["Max Temp"])
regress_values = n_hemisphere["Lat"] * slope + intercept

# Scatter Plot
x_axis = n_hemisphere["Lat"]
y_axis = n_hemisphere["Max Temp"]
plt.scatter(x_axis, y_axis, edgecolor="black")

# Regression Line
plt.plot(n_hemisphere["Lat"], regress_values, color='red')
line_eq = f"y = {round(slope, 2)}x + {round(intercept, 2)}"
r_value = f"r = {round(rvalue,2)}"
plt.annotate(line_eq, (5,35), color='red', fontsize=10)
plt.annotate(r_value, (5,32), color='red', fontsize=10)

# Labels
plt.title("Max Temp vs. Latitude (Northern Hemisphere)")
plt.xlabel("Latitude")
plt.ylabel("Max Temp (F)")
print(f"The r-squared is: {rvalue}")
plt.savefig("TempVLat-NHemisphere.png")
plt.show()<jupyter_output>The r-squared is: -0.686210258038039<jupyter_text>Southern Hemisphere - Max Temp vs. Latitude Linear Regression<jupyter_code># Calculate the correlation coefficient and linear regression model 
(slope, intercept,rvalue, pvalue, stderr) = linregress(s_hemisphere["Lat"], s_hemisphere["Max Temp"])
regress_values = s_hemisphere["Lat"] * slope + intercept

# Scatter Plot
x_axis = s_hemisphere["Lat"]
y_axis = s_hemisphere["Max Temp"]
plt.scatter(x_axis, y_axis, edgecolor="black")

# Regression Line
plt.plot(s_hemisphere["Lat"], regress_values, color='red')
line_eq = f"y = {round(slope, 2)}x + {round(intercept, 2)}"
r_value = f"r = {round(rvalue,2)}"
plt.annotate(line_eq, (-50,80), color='red', fontsize=10)
plt.annotate(r_value, (-50,75), color='red', fontsize=10)

# Labels
plt.title("Max Temp vs. Latitude (Southern Hemisphere)")
plt.xlabel("Latitude")
plt.ylabel("Max Temp (F)")
print(f"The r-squared is: {rvalue}")
plt.savefig("TempVLat-SHemisphere.png")
plt.show()<jupyter_output>The r-squared is: 0.799509869125586<jupyter_text>Northern Hemisphere - Humidity (%) vs. Latitude Linear Regression<jupyter_code># Calculate the correlation coefficient and linear regression model 
(slope, intercept,rvalue, pvalue, stderr) = linregress(n_hemisphere["Lat"], n_hemisphere["Humidity"])
regress_values = n_hemisphere["Lat"] * slope + intercept

# Scatter Plot
x_axis = n_hemisphere["Lat"]
y_axis = n_hemisphere["Humidity"]
plt.scatter(x_axis, y_axis, edgecolor="black")

# Regression Line
plt.plot(n_hemisphere["Lat"], regress_values, color='red')
line_eq = f"y = {round(slope, 2)}x + {round(intercept, 2)}"
r_value = f"r = {round(rvalue,2)}"
plt.annotate(line_eq, (0,20), color='red', fontsize=10)
plt.annotate(r_value, (0,10), color='red', fontsize=10)

# Labels
plt.title("Max Temp vs. Humidity (Northern Hemisphere)")
plt.xlabel("Latitude")
plt.ylabel("Max Temp (F)")
print(f"The r-squared is: {rvalue}")
plt.savefig("HumidityVLat-NHemisphere.png")
plt.show()<jupyter_output>The r-squared is: -0.08703486756193805<jupyter_text>Southern Hemisphere - Humidity (%) vs. Latitude Linear Regression<jupyter_code># Calculate the correlation coefficient and linear regression model 
(slope, intercept,rvalue, pvalue, stderr) = linregress(s_hemisphere["Lat"], s_hemisphere["Humidity"])
regress_values = s_hemisphere["Lat"] * slope + intercept

# Scatter Plot
x_axis = s_hemisphere["Lat"]
y_axis = s_hemisphere["Humidity"]
plt.scatter(x_axis, y_axis, edgecolor="black")

# Regression Line
plt.plot(s_hemisphere["Lat"], regress_values, color='red')
line_eq = f"y = {round(slope, 2)}x + {round(intercept, 2)}"
r_value = f"r = {round(rvalue,2)}"
plt.annotate(line_eq, (-55,35), color='red', fontsize=10)
plt.annotate(r_value, (-55,30), color='red', fontsize=10)

# Labels
plt.title("Max Temp vs. Humidity (Southern Hemisphere)")
plt.xlabel("Latitude")
plt.ylabel("Max Temp (F)")
print(f"The r-squared is: {rvalue}")
plt.savefig("HumidityVLat-SHemisphere.png")
plt.show()<jupyter_output>The r-squared is: 0.18330860382632286<jupyter_text>Northern Hemisphere - Cloudiness (%) vs. Latitude Linear Regression<jupyter_code># Calculate the correlation coefficient and linear regression model 
(slope, intercept,rvalue, pvalue, stderr) = linregress(n_hemisphere["Lat"], n_hemisphere["Cloudiness"])
regress_values = n_hemisphere["Lat"] * slope + intercept

# Scatter Plot
x_axis = n_hemisphere["Lat"]
y_axis = n_hemisphere["Cloudiness"]
plt.scatter(x_axis, y_axis, edgecolor="black")

# Regression Line
plt.plot(n_hemisphere["Lat"], regress_values, color='red')
line_eq = f"y = {round(slope, 2)}x + {round(intercept, 2)}"
r_value = f"r = {round(rvalue,2)}"
plt.annotate(line_eq, (25,55), color='red', fontsize=10)
plt.annotate(r_value, (25,50), color='red', fontsize=10)

# Labels
plt.title("Max Temp vs. Cloudiness (Northern Hemisphere)")
plt.xlabel("Latitude")
plt.ylabel("Max Temp (F)")
print(f"The r-squared is: {rvalue}")
plt.savefig("CloudinessVLat-NHemisphere.png")
plt.show()<jupyter_output>The r-squared is: -0.03251686359033089<jupyter_text>Southern Hemisphere - Cloudiness (%) vs. Latitude Linear Regression<jupyter_code># Calculate the correlation coefficient and linear regression model 
(slope, intercept,rvalue, pvalue, stderr) = linregress(s_hemisphere["Lat"], s_hemisphere["Cloudiness"])
regress_values = s_hemisphere["Lat"] * slope + intercept

# Scatter Plot
x_axis = s_hemisphere["Lat"]
y_axis = s_hemisphere["Cloudiness"]
plt.scatter(x_axis, y_axis, edgecolor="black")

# Regression Line
plt.plot(s_hemisphere["Lat"], regress_values, color='red')
line_eq = f"y = {round(slope, 2)}x + {round(intercept, 2)}"
r_value = f"r = {round(rvalue,2)}"
plt.annotate(line_eq, (-55,50), color='red', fontsize=10)
plt.annotate(r_value, (-55,40), color='red', fontsize=10)

# Labels
plt.title("Max Temp vs. Cloudiness (Southern Hemisphere)")
plt.xlabel("Latitude")
plt.ylabel("Max Temp (F)")
print(f"The r-squared is: {rvalue}")
plt.savefig("CloudinessVLat-SHemisphere.png")
plt.show()<jupyter_output>The r-squared is: 0.07783499359437623<jupyter_text>Northern Hemisphere - Wind Speed (mph) vs. Latitude Linear Regression<jupyter_code># Calculate the correlation coefficient and linear regression model 
(slope, intercept,rvalue, pvalue, stderr) = linregress(n_hemisphere["Lat"], n_hemisphere["Wind Speed"])
regress_values = n_hemisphere["Lat"] * slope + intercept

# Scatter Plot
x_axis = n_hemisphere["Lat"]
y_axis = n_hemisphere["Wind Speed"]
plt.scatter(x_axis, y_axis, edgecolor="black")

# Regression Line
plt.plot(n_hemisphere["Lat"], regress_values, color='red')
line_eq = f"y = {round(slope, 2)}x + {round(intercept, 2)}"
r_value = f"r = {round(rvalue,2)}"
plt.annotate(line_eq, (0,35), color='red', fontsize=10)
plt.annotate(r_value, (0,32), color='red', fontsize=10)

# Labels
plt.title("Max Temp vs. Wind Speed (Northern Hemisphere)")
plt.xlabel("Latitude")
plt.ylabel("Max Temp (F)")
print(f"The r-squared is: {rvalue}")
plt.savefig("WindVLat-NHemisphere.png")
plt.show()<jupyter_output>The r-squared is: 0.0468508307445828<jupyter_text>Southern Hemisphere - Wind Speed (mph) vs. Latitude Linear Regression<jupyter_code># Calculate the correlation coefficient and linear regression model 
(slope, intercept,rvalue, pvalue, stderr) = linregress(s_hemisphere["Lat"], s_hemisphere["Wind Speed"])
regress_values = s_hemisphere["Lat"] * slope + intercept

# Scatter Plot
x_axis = s_hemisphere["Lat"]
y_axis = s_hemisphere["Wind Speed"]
plt.scatter(x_axis, y_axis, edgecolor="black")

# Regression Line
plt.plot(s_hemisphere["Lat"], regress_values, color='red')
line_eq = f"y = {round(slope, 2)}x + {round(intercept, 2)}"
r_value = f"r = {round(rvalue,2)}"
plt.annotate(line_eq, (-25,23), color='red', fontsize=10)
plt.annotate(r_value, (-25,21), color='red', fontsize=10)

# Labels
plt.title("Max Temp vs. Wind Speed (Southern Hemisphere)")
plt.xlabel("Latitude")
plt.ylabel("Max Temp (F)")
print(f"The r-squared is: {rvalue}")
plt.savefig("WindVLat-SHemisphere.png")
plt.show()<jupyter_output>The r-squared is: -0.28581453249400496
{'fraction_non_alphanumeric': 0.14844626245299203, 'fraction_numerical': 0.02526885267533153, 'mean_word_length': 5.953211009174312, 'pattern_counts': {'":': 9, '<': 68, '<?xml version=': 0, '>': 70, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '14404', 'license': 'ADSL', 'n_tokens_mistral': 5842, 'n_tokens_neox': 5300, 'n_words': 1291, 'path': 'WeatherPy/WeatherPy.ipynb', 'repo_name': 'ejkaster/06-python-api-challenge', 'size': '15165'}