<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 pandas as pd
from citipy import citipy
import matplotlib.pyplot as plt
import numpy as np
import os
from pprint import pprint
import requests
from api_keys import weather_api_key
from scipy.stats import linregress<jupyter_output><empty_output><jupyter_text>Generate Cities List<jupyter_code>cities = []
locations = []
latitudes = np.random.uniform(-90, 90, size=1500)
longitudes = np.random.uniform(-180, 180, size=1500)
locations = zip(latitudes, longitudes)
for coordinate_pair in locations:
    lat, lon = coordinate_pair
    city = citipy.nearest_city(coordinate_pair[0], coordinate_pair[1]).city_name
    if city not in cities: 
        cities.append(city)
print(len(cities))<jupyter_output>586<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>Lat = []
Long = []
Max_Temp = []
Humidity = []
Cloudiness = []
Wind_Speed = []
Country = []
Date = []
cities_found = []


for city in cities:
    url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={weather_api_key}&units=Imperial"
    try: 
        weather = requests.get(url).json()
        Max_Temp.append(weather["main"]["temp_max"])
        Lat.append(weather["coord"]["lat"])
        Long.append(weather["coord"]["lon"])
        Humidity.append(weather["main"]["humidity"])
        Cloudiness.append(weather["clouds"]["all"])
        Wind_Speed.append(weather["wind"]["speed"])
        Country.append(weather["sys"]["country"])
        Date.append(weather["dt"])
        cities_found.append(city)
        print(city)
    except:
        print("City weather not found " + city)
cities_df = pd.DataFrame({"City": cities_found, "Lat": Lat, "Lng": Long, "Max Temp": Max_Temp, 
                         "Humidity": Humidity, "Cloudiness": Cloudiness, "Wind Speed": Wind_Speed, 
                         "Country": Country, "Date": Date}) 
cities_df.head(150)<jupyter_output>akom
mar del plata
bambous virieux
port alfred
nikolskoye
ushuaia
rocha
thompson
udachnyy
jamestown
avarua
lagoa
manado
quatre cocos
bograd
kiama
rikitea
sault sainte marie
City weather not found attawapiskat
kodiak
empangeni
City weather not found mutsamudu
barrow
akyab
viedma
kaitangata
punta arenas
kisangani
longyearbyen
khatanga
cape town
cidreira
bengkulu
omis
victoria
airai
hobart
sibolga
vaini
cazanesti
yanam
hilo
norman wells
albany
vestmannaeyjar
saint george
remanso
babu
daru
castro
port elizabeth
City weather not found illoqqortoormiut
kristianstad
keffi
hithadhoo
makokou
hermanus
yellowknife
dingle
ixtapa
tuatapere
comodoro rivadavia
cabo san lucas
don sak
kapaa
kruisfontein
trinidad
pangnirtung
tadine
harrisonville
jiuquan
City weather not found taolanaro
codrington
lebu
qaanaaq
ponta do sol
ikwiriri
san patricio
new norfolk
City weather not found meyungs
mouila
axim
butaritari
havre-saint-pierre
mackenzie
City weather not found tumannyy
terracina
dikson
richards bay
paita[...]<jupyter_text>Convert Raw Data to DataFrame* Export the city data into a .csv.* Display the DataFrame<jupyter_code>#saving City DataFrame as CSV file
cities_df.to_csv('output_data\city_data.csv', index = False)

file_path = os.path.join("output_data", "city_data.csv")
df = pd.read_csv(file_path)
df.head()
cities_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>#nothing greater than 100% as shown by max humidity value<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>from datetime import date
    lat = cities_df["Lat"]
    max_temp = cities_df["Max Temp"]
    plt.scatter(lat, max_temp, color='DarkBlue')
    plt.title(f"City Latitude vs Max Temperature ({date.today()})")
    plt.xlabel("Latitude")
    plt.ylabel("Max Temperature (F)")
    plt.grid(True)
    plt.tight_layout()
    plt.savefig("output_data/CityLatVMaxtemp")
    plt.show()<jupyter_output><empty_output><jupyter_text>Latitude vs. Humidity Plot<jupyter_code>lat = cities_df["Lat"]
    hum = cities_df["Humidity"]
    plt.scatter(lat, hum, color='DarkBlue')
    plt.title(f"City Latitude vs Humidity ({date.today()})")
    plt.xlabel("Latitude")
    plt.ylabel("Humidity (%)")
    plt.grid(True)
    plt.tight_layout()
    plt.savefig("output_data/CityLatVHumidity")
    plt.show()<jupyter_output><empty_output><jupyter_text>Latitude vs. Cloudiness Plot<jupyter_code>lat = cities_df["Lat"]
    cloud = cities_df["Cloudiness"]
    plt.scatter(lat, cloud, color='DarkBlue')
    plt.title(f"City Latitude vs Cloudiness ({date.today()})")
    plt.xlabel("Latitude")
    plt.ylabel("Cloudiness (%)")
    plt.grid(True)
    plt.tight_layout()
    plt.savefig("output_data/CityLatVCloudiness")
    plt.show()<jupyter_output><empty_output><jupyter_text>Latitude vs. Wind Speed Plot<jupyter_code>lat = cities_df["Lat"]
    wspeed = cities_df["Wind Speed"]
    plt.scatter(lat, wspeed, color='DarkBlue')
    plt.title(f"City Latitude vs Wind Speed ({date.today()})")
    plt.xlabel("Latitude")
    plt.ylabel("Wind Speed (mph)")
    plt.grid(True)
    plt.tight_layout()
    plt.savefig("output_data/CityLatVWindSpeed")
    plt.show()<jupyter_output><empty_output><jupyter_text>Linear Regression<jupyter_code>#Seperate Northern and Southern Hemispheres
north_hem_df = cities_df.loc[(cities_df["Lat"]>0)]
south_hem_df = cities_df.loc[(cities_df["Lat"]<0)]
#Northern Hemisphere - Max Temp vs. Latitude Linear Regression

#name x and y data for slope
x_values = north_hem_df['Lat']
y_values = north_hem_df['Max Temp']
#run regression and store returned values
slope, intercept, rvalue, pvalue, stderr = linregress(x_values, y_values)
# Calculate the predictions for each value of x 
regression_values = x_values * slope + intercept
# store the string version of said linear equation, to be displayed on plot
line_eq = "y = " + str(round(slope,2)) + "x + " + str(round(intercept,2))
#format and show plot with best fit line and slope showing
plt.figure(figsize=(10,8))
plt.scatter(x_values, y_values)
plt.plot(x_values,regression_values,"red")
plt.annotate(line_eq, (18,45), fontsize=15, color="red")
plt.title("Northern Hemisphere - Max Temp vs. Latitude")
plt.xlabel("Latitude")
plt.ylabel("Max Temp (F)")
print(f"The measure of the proportion of variability in the data, r^2 is: {rvalue**2}")
plt.savefig("output_data/NHmxtempVlat.png")
plt.show()
#Southern Hemisphere - Max Temp vs. Latitude Linear Regression

#name x and y data for slope
x_values = south_hem_df['Lat']
y_values = south_hem_df['Max Temp']
#run regression and store returned values
slope, intercept, rvalue, pvalue, stderr = linregress(x_values, y_values)
# Calculate the predictions for each value of x 
regression_values = x_values * slope + intercept
# store the string version of said linear equation, to be displayed on plot
line_eq = "y = " + str(round(slope,2)) + "x + " + str(round(intercept,2))
#format and show plot with best fit line and slope showing
plt.figure(figsize=(10,8))
plt.scatter(x_values, y_values)
plt.plot(x_values,regression_values,"red")
plt.annotate(line_eq, (18,45), fontsize=15, color="red")
plt.title("Southern Hemisphere - Max Temp vs. Latitude")
plt.xlabel("Latitude")
plt.ylabel("Max Temp (F)")
print(f"The measure of the proportion of variability in the data, r^2 is: {rvalue**2}")
plt.savefig("output_data/SHmxtempVlat.png")
plt.show()<jupyter_output>The measure of the proportion of variability in the data, r^2 is: 0.5508541208594598<jupyter_text>Northern Hemisphere - Max Temp vs. Latitude Linear Regression   Northern Hemisphere - Humidity (%) vs. Latitude Linear Regression<jupyter_code>#Northern Hemisphere - Humidity vs. Latitude Linear Regression
#name x and y data for slope
x_values = north_hem_df['Lat']
y_values = north_hem_df['Humidity']
#run regression and store returned values
slope, intercept, rvalue, pvalue, stderr = linregress(x_values, y_values)
# Calculate the predictions for each value of x 
regression_values = x_values * slope + intercept
# store the string version of said linear equation, to be displayed on plot
line_eq = "y = " + str(round(slope,2)) + "x + " + str(round(intercept,2))
#format and show plot with best fit line and slope showing
plt.figure(figsize=(10,8))
plt.scatter(x_values, y_values)
plt.plot(x_values,regression_values,"red")
plt.annotate(line_eq, (50,65), fontsize=15, color="red")
plt.title("Northern Hemisphere - Humidity vs. Latitude")
plt.xlabel("Latitude")
plt.ylabel("Max Temp (F)")
print(f"The measure of the proportion of variability in the data, r^2 is: {rvalue**2}")
plt.savefig("output_data/NHhumidVlat.png")
plt.show()<jupyter_output>The measure of the proportion of variability in the data, r^2 is: 5.559576872545659e-05<jupyter_text>Southern Hemisphere - Humidity (%) vs. Latitude Linear Regression<jupyter_code>#Southern Hemisphere - Humidity vs. Latitude Linear Regression
#name x and y data for slope
x_values = south_hem_df['Lat']
y_values = south_hem_df['Humidity']
#run regression and store returned values
slope, intercept, rvalue, pvalue, stderr = linregress(x_values, y_values)
# Calculate the predictions for each value of x 
regression_values = x_values * slope + intercept
# store the string version of said linear equation, to be displayed on plot
line_eq = "y = " + str(round(slope,2)) + "x + " + str(round(intercept,2))
#format and show plot with best fit line and slope showing
plt.figure(figsize=(10,8))
plt.scatter(x_values, y_values)
plt.plot(x_values,regression_values,"red")
plt.annotate(line_eq, (-20,75), fontsize=15, color="red")
plt.title("Southern Hemisphere - Humidity vs. Latitude")
plt.xlabel("Latitude")
plt.ylabel("Max Temp (F)")
print(f"The measure of the proportion of variability in the data, r^2 is: {rvalue**2}")
plt.savefig("output_data/SHhumidVlat.png")
plt.show()<jupyter_output>The measure of the proportion of variability in the data, r^2 is: 0.002383283291730476<jupyter_text>Northern Hemisphere - Cloudiness (%) vs. Latitude Linear Regression<jupyter_code>#Northern Hemisphere - Cloudiness vs. Latitude Linear Regression
#name x and y data for slope
x_values = north_hem_df['Lat']
y_values = north_hem_df['Cloudiness']
#run regression and store returned values
slope, intercept, rvalue, pvalue, stderr = linregress(x_values, y_values)
# Calculate the predictions for each value of x
regression_values = x_values * slope + intercept
# store the string version of said linear equation, to be displayed on plot
line_eq = "y = " + str(round(slope,2)) + "x + " + str(round(intercept,2))
#format and show plot with best fit line and slope showing
plt.figure(figsize=(10,8))
plt.scatter(x_values, y_values)
plt.plot(x_values,regression_values,"red")
plt.annotate(line_eq, (50,65), fontsize=15, color="red")
plt.title("Northern Hemisphere - Cloudiness vs. Latitude")
plt.xlabel("Latitude")
plt.ylabel("Max Temp (F)")
print(f"The measure of the proportion of variability in the data, r^2 is: {rvalue**2}")
plt.savefig("output_data/NHcloudVlat.png")
plt.show()<jupyter_output>The measure of the proportion of variability in the data, r^2 is: 0.005739835896437981<jupyter_text>Southern Hemisphere - Cloudiness (%) vs. Latitude Linear Regression<jupyter_code>#Southern Hemisphere - Cloudiness vs. Latitude Linear Regression
#name x and y data for slope
#name x and y data for slope
x_values = south_hem_df['Lat']
y_values = south_hem_df['Cloudiness']
#run regression and store returned values
slope, intercept, rvalue, pvalue, stderr = linregress(x_values, y_values)
# Calculate the predictions for each value of x (Weight (g))
regression_values = x_values * slope + intercept
# store the string version of said linear equation, to be displayed on plot
line_eq = "y = " + str(round(slope,2)) + "x + " + str(round(intercept,2))
#format and show plot with best fit line and slope showing
plt.figure(figsize=(10,8))
plt.scatter(x_values, y_values)
plt.plot(x_values,regression_values,"red")
plt.annotate(line_eq, (-20, 65), fontsize=15, color="red")
plt.title("Southern Hemisphere - Cloudiness vs. Latitude")
plt.xlabel("Latitude")
plt.ylabel("Max Temp (F)")
print(f"The measure of the proportion of variability in the data, r^2 is: {rvalue**2}")
plt.savefig("output_data/SHcloudVlat.png")
plt.show()<jupyter_output>The measure of the proportion of variability in the data, r^2 is: 4.974519155201529e-06<jupyter_text>Northern Hemisphere - Wind Speed (mph) vs. Latitude Linear Regression<jupyter_code>#Northern Hemisphere - Wind Speed vs. Latitude Linear Regression
#name x and y data for slope
x_values = north_hem_df['Lat']
y_values = north_hem_df['Wind Speed']
#run regression and store returned values
slope, intercept, rvalue, pvalue, stderr = linregress(x_values, y_values)
# Calculate the predictions for each value of x
regression_values = x_values * slope + intercept
# store the string version of said linear equation, to be displayed on plot
line_eq = "y = " + str(round(slope,2)) + "x + " + str(round(intercept,2))
#format and show plot with best fit line and slope showing
plt.figure(figsize=(10,8))
plt.scatter(x_values, y_values)
plt.plot(x_values,regression_values,"red")
plt.annotate(line_eq, (55, 10), fontsize=15, color="red")
plt.title("Northern Hemisphere - Wind Speed vs. Latitude")
plt.xlabel("Latitude")
plt.ylabel("Max Temp (F)")
print(f"The measure of the proportion of variability in the data, r^2 is: {rvalue**2}")
plt.savefig("output_data/NHwdsppVlat.png")
plt.show()<jupyter_output>The measure of the proportion of variability in the data, r^2 is: 0.04275021533274159<jupyter_text>Southern Hemisphere - Wind Speed (mph) vs. Latitude Linear Regression<jupyter_code>#Southern Hemisphere - Wind Speed vs. Latitude Linear Regression
#name x and y data for slope
x_values = south_hem_df['Lat']
y_values = south_hem_df['Wind Speed']
#run regression and store returned values
slope, intercept, rvalue, pvalue, stderr = linregress(x_values, y_values)
# Calculate the predictions for each value of x 
regression_values = x_values * slope + intercept
# store the string version of said linear equation, to be displayed on plot
line_eq = "y = " + str(round(slope,2)) + "x + " + str(round(intercept,2))
#format and show plot with best fit line and slope showing
plt.figure(figsize=(10,8))
plt.scatter(x_values, y_values)
plt.plot(x_values,regression_values,"red")
plt.annotate(line_eq, (-20, 15), fontsize=15, color="red")
plt.title("Southern Hemisphere - Wind Speed vs. Latitude")
plt.xlabel("Latitude")
plt.ylabel("Max Temp (F)")
print(f"The measure of the proportion of variability in the data, r^2 is: {rvalue**2}")
plt.savefig("output_data/SHwdsppVlat.png")
plt.show()<jupyter_output>The measure of the proportion of variability in the data, r^2 is: 0.0622632997861007
{'fraction_non_alphanumeric': 0.11345006229916715, 'fraction_numerical': 0.01809954751131222, 'mean_word_length': 5.662297946701616, 'pattern_counts': {'":': 9, '<': 57, '<?xml version=': 0, '>': 59, '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': '16', 'dir': 'jupyter-structured-clean-dedup', 'id': '161067', 'license': 'ADSL', 'n_tokens_mistral': 5517, 'n_tokens_neox': 5123, 'n_words': 1484, 'path': 'WeatherPy.ipynb', 'repo_name': 'SBBoudreau/Python-API-Challenge', 'size': '15249'}