<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 datetime
from datetime import date
from scipy.stats import linregress
import pprint as pp


# Import API key
from api_key import weather_api_key
url = "http://api.openweathermap.org/data/2.5/weather?"
units = "imperial"

# Incorporated citipy to determine city based on latitude and longitude
from citipy import citipy
query_url = f"{url}appid={weather_api_key}&units={units}&q="

# 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>pd.read_csv(output_data_file)
# 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
cities_df=pd.DataFrame(cities)
cities_df.to_csv(output_data_file)
cities_df=cities_df.rename(columns={0:"City"})

cities_df["Cloudiness"]=""
cities_df["Country"]=""
cities_df["Date"]=""
cities_df["Humidity"]=""
cities_df["Lat"]=""
cities_df["Long"]=""
cities_df["Max Temp"]=""
cities_df["Wind Speed"]=""

cities_df<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>base_url = "https://api.openweathermap.org/data/2.5/weather?appid=" + weather_api_key
print(requests.get(base_url + '&q=' + 'new york' + '&units=imperial').json())
temp=[]

record=1
sets=1



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

for index, row in cities_df.iterrows():
    city = row['City']
    
    if (record%50)==0:
        record=1
        sets +=1
    else:
        record+=1 
    response = requests.get(query_url + city).json()
    print(f"Processing Record {record-1} of Set {sets} | {city} ")
    
    if response["cod"]!="404" and response["cod"]!="500" :
        cities_df.loc[index, "Cloudiness"]=response["clouds"]["all"]
        cities_df.loc[index, "Country"]=response["sys"]["country"]
        current_date=datetime.datetime.fromtimestamp(response["dt"]).strftime("%x")
        cities_df.loc[index, "Date"]=response["dt"]
        cities_df.loc[index, "Humidity"]=response["main"]["humidity"]
        cities_df.loc[index, "Lat"]=float(response["coord"]["lat"])
        cities_df.loc[index, "Long"]=response["coord"]["lon"]
        cities_df.loc[index, "Max Temp"]=float(response["main"]["temp_max"])
        cities_df.loc[index, "Wind Speed"]=response["wind"]["speed"]
    else:
        print("City Not Found")
    
print("-----------------------------")        
print("Data Retrieval Complete")
print("-----------------------------")<jupyter_output>Beginning Data Retrieval
-----------------------------
Processing Record 1 of Set 1 | saint-philippe 
Processing Record 2 of Set 1 | ushuaia 
Processing Record 3 of Set 1 | ahipara 
Processing Record 4 of Set 1 | saint-gilles 
Processing Record 5 of Set 1 | zima 
Processing Record 6 of Set 1 | bengkulu 
Processing Record 7 of Set 1 | cape town 
Processing Record 8 of Set 1 | esperance 
Processing Record 9 of Set 1 | oliveira 
Processing Record 10 of Set 1 | vangaindrano 
Processing Record 11 of Set 1 | albany 
Processing Record 12 of Set 1 | anadyr 
Processing Record 13 of Set 1 | saint-joseph 
Processing Record 14 of Set 1 | umzimvubu 
City Not Found
Processing Record 15 of Set 1 | nishihara 
Processing Record 16 of Set 1 | dawei 
Processing Record 17 of Set 1 | punta arenas 
Processing Record 18 of Set 1 | ponta do sol 
Processing Record 19 of Set 1 | tawzar 
City Not Found
Processing Record 20 of Set 1 | bluff 
Processing Record 21 of Set 1 | butaritari 
Processing Record 22 of Set [...]<jupyter_text>Convert Raw Data to DataFrameExport the city data into a .csv.Display the DataFrame<jupyter_code>cities_df.head()
cities_df.to_csv("cities_fullframe.csv")
cities_df.head()
cities_df["Lat"]=pd.to_numeric(cities_df["Lat"])
cities_df["Max Temp"]=pd.to_numeric(cities_df["Max Temp"])
cities_df["Humidity"]=pd.to_numeric(cities_df["Humidity"])
cities_df["Wind Speed"]=pd.to_numeric(cities_df["Wind Speed"])
cities_df["Cloudiness"]=pd.to_numeric(cities_df["Cloudiness"])
ymax=cities_df["Max Temp"].max()+10
ymin=cities_df["Max Temp"].min()-10
xmax=cities_df["Lat"].max()+10
xmin=cities_df["Lat"].min()+10<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.xlim(xmin,xmax)
plt.ylim(ymin,ymax)

plt.title(f"City latitude vs Max temperature {current_date}")
plt.xlabel("Latitude")
plt.ylabel("Max Temperature (F)")
plt.scatter(cities_df["Lat"], cities_df["Max Temp"],marker="o", alpha=.8,linewidths=1, color="teal", edgecolors='blue',label="Urban")

plt.grid()
plt.tight_layout()

plt.savefig("latitude_Temp.png")
plt.show()<jupyter_output><empty_output><jupyter_text>Latitude vs. Humidity Plot<jupyter_code>ymax=100+10
ymin=cities_df["Humidity"].min()-5
plt.xlim(xmin,xmax)
plt.ylim(ymin,ymax)

plt.title(f"City Latitude vs. Humidity Plot {current_date}")
plt.xlabel("Latitude")
plt.ylabel("Humidity (%)")
plt.scatter(cities_df["Lat"], cities_df["Humidity"],marker="o", alpha=.6,linewidths=1, color="blue", edgecolors='black',label="Urban")

plt.grid()

plt.savefig("latitude_Humidty.png")
plt.show()<jupyter_output><empty_output><jupyter_text>Latitude vs. Cloudiness Plot<jupyter_code>ymax=cities_df["Cloudiness"].max()+10
ymin=cities_df["Cloudiness"].min()-5
plt.xlim(xmin,xmax)
plt.ylim(ymin,ymax)

plt.title(f"City Latitude vs. Cloudiness {current_date}")
plt.xlabel("Latitude")
plt.ylabel("Cloudiness (%)")

plt.scatter(cities_df["Lat"], cities_df["Cloudiness"],marker="o", alpha=.6,linewidths=1, color="blue", edgecolors='black',label="Urban")

plt.grid()

plt.savefig("latitude_Cloudiness.png")
plt.show()<jupyter_output><empty_output><jupyter_text>Latitude vs. Wind Speed Plot<jupyter_code>ymax=cities_df["Wind Speed"].max()+10
ymin=cities_df["Wind Speed"].min()-5
plt.xlim(xmin,xmax)
plt.ylim(ymin,ymax)

plt.title(f"City Latitude vs. Wind Speed {current_date}")
plt.xlabel("Latitude")
plt.ylabel("Wind Speed (mph))")

plt.scatter(cities_df["Lat"], cities_df["Wind Speed"],marker="o", alpha=.6,linewidths=1, color="blue", edgecolors='black',label="Urban")

plt.grid()


plt.savefig("latitude_Wind_Speed.png")
plt.show()<jupyter_output><empty_output><jupyter_text>Linear Regression<jupyter_code>northern_df = cities_df.loc[pd.to_numeric(cities_df["Lat"]).astype(float) > 0, :]
southern_df = cities_df.loc[pd.to_numeric(cities_df["Lat"]).astype(float) < 0, :]<jupyter_output><empty_output><jupyter_text>Northern Hemisphere - Max Temp vs. Latitude Linear Regression<jupyter_code>x_values=northern_df['Lat']

y_values = northern_df['Max Temp']


(slope, intercept, rvalue, pvalue, stderr) = linregress(x_values, y_values)
regress_values = x_values * slope + intercept
line_eq = "y = " + str(round(slope,2)) + "x + " + str(round(intercept,2))
plt.scatter(x_values,y_values)
plt.plot(x_values,regress_values,"r-")
plt.annotate(line_eq,(0,50),fontsize=15,color="red")
plt.xlabel('Latitude')
plt.ylabel('Max Temp')
print(f"The r-squared is: {rvalue}")
plt.show()<jupyter_output>The r-squared is: -0.9005747679894786<jupyter_text>Southern Hemisphere - Max Temp vs. Latitude Linear Regression<jupyter_code>x_values = pd.to_numeric(southern_df['Lat']).astype(float)
y_values = pd.to_numeric(southern_df['Max Temp']).astype(float)
(slope, intercept, rvalue, pvalue, stderr) = linregress(x_values, y_values)
regress_values = x_values * slope + intercept
line_eq = "y = " + str(round(slope,2)) + "x + " + str(round(intercept,2))
print(f"Regression line equation is: {line_eq}")
plt.scatter(x_values,y_values)
plt.plot(x_values,regress_values,"r-")
plt.annotate(line_eq,(6,10),fontsize=15,color="red")
plt.xlabel('Latitude')
plt.ylabel('Max Temperature (F)')
plt.title('Southern Hemisphere - Max Temp vs. Latitude Linear Regression')
print(f"The r-squared is: {rvalue}")
print("The regression displays a positive correlation.")
print("In the southern hemisphere, as you get closer to the equator the temperature increases.")
plt.show()<jupyter_output>Regression line equation is: y = 0.43x + 82.47
The r-squared is: 0.5423531231864076
The regression displays a positive correlation.
In the southern hemisphere, as you get closer to the equator the temperature increases.<jupyter_text>Northern Hemisphere - Humidity (%) vs. Latitude Linear Regression<jupyter_code>x_values = pd.to_numeric(northern_df['Lat']).astype(float)
y_values = pd.to_numeric(northern_df['Humidity']).astype(float)
(slope, intercept, rvalue, pvalue, stderr) = linregress(x_values, y_values)
regress_values = x_values * slope + intercept
line_eq = "y = " + str(round(slope,2)) + "x + " + str(round(intercept,2))
print(f"Regression line equation is: {line_eq}")
plt.scatter(x_values,y_values)
plt.plot(x_values,regress_values,"r-")
plt.annotate(line_eq,(6,10),fontsize=15,color="red")
plt.xlabel('Latitude')
plt.ylabel('Humidity (%)')
plt.title('Northern Hemisphere - Humidity (%) vs. Latitude Linear Regression')
print(f"The r-squared is: {rvalue}")
print("The regression does not display much of a correlation between the data sets.") 
plt.show()<jupyter_output>Regression line equation is: y = 0.27x + 57.8
The r-squared is: 0.23981016229440066
The regression does not display much of a correlation between the data sets.<jupyter_text>Southern Hemisphere - Humidity (%) vs. Latitude Linear Regression<jupyter_code>x_values = pd.to_numeric(southern_df['Lat']).astype(float)
y_values = pd.to_numeric(southern_df['Humidity']).astype(float)
(slope, intercept, rvalue, pvalue, stderr) = linregress(x_values, y_values)
regress_values = x_values * slope + intercept
line_eq = "y = " + str(round(slope,2)) + "x + " + str(round(intercept,2))
print(f"Regression line equation is: {line_eq}")
plt.scatter(x_values,y_values)
plt.plot(x_values,regress_values,"r-")
plt.annotate(line_eq,(6,10),fontsize=15,color="red")
plt.xlabel('Latitude')
plt.ylabel('Humidity (%)')
plt.title('Southern Hemisphere - Humidity (%) vs. Latitude Linear Regression')
print(f"The r-squared is: {rvalue}")
print("The regression does not display much of a correlation between the data sets.")
plt.show()<jupyter_output>Regression line equation is: y = 0.32x + 81.34
The r-squared is: 0.26207970612626946
The regression does not display much of a correlation between the data sets.<jupyter_text>Northern Hemisphere - Cloudiness (%) vs. Latitude Linear Regression<jupyter_code>x_values = pd.to_numeric(northern_df['Lat']).astype(float)
y_values = pd.to_numeric(northern_df['Cloudiness']).astype(float)
(slope, intercept, rvalue, pvalue, stderr) = linregress(x_values, y_values)
regress_values = x_values * slope + intercept
line_eq = "y = " + str(round(slope,2)) + "x + " + str(round(intercept,2))
print(f"Regression line equation is: {line_eq}")
plt.scatter(x_values,y_values)
plt.plot(x_values,regress_values,"r-")
plt.annotate(line_eq,(6,10),fontsize=15,color="red")
plt.xlabel('Latitude')
plt.ylabel('Cloudiness (%)')
plt.title('Northern Hemisphere - Cloudiness (%) vs. Latitude Linear Regression')
print(f"The r-squared is: {rvalue}")
print("The regression does not display much of a correlation between the data sets.")
plt.show()<jupyter_output>Regression line equation is: y = 0.41x + 34.57
The r-squared is: 0.20791640553357435
The regression does not display much of a correlation between the data sets.<jupyter_text>Southern Hemisphere - Cloudiness (%) vs. Latitude Linear Regression<jupyter_code>x_values = pd.to_numeric(southern_df['Lat']).astype(float)
y_values = pd.to_numeric(southern_df['Cloudiness']).astype(float)
(slope, intercept, rvalue, pvalue, stderr) = linregress(x_values, y_values)
regress_values = x_values * slope + intercept
line_eq = "y = " + str(round(slope,2)) + "x + " + str(round(intercept,2))
print(f"Regression line equation is: {line_eq}")
plt.scatter(x_values,y_values)
plt.plot(x_values,regress_values,"r-")
plt.annotate(line_eq,(6,10),fontsize=15,color="red")
plt.xlabel('Latitude')
plt.ylabel('Cloudiness (%)')
plt.title('Southern Hemisphere - Cloudiness (%) vs. Latitude Linear Regression')
print(f"The r-squared is: {rvalue}")
print("The regression does not display much of a correlation between the data sets.")
plt.show()<jupyter_output>Regression line equation is: y = 1.07x + 68.19
The r-squared is: 0.3943450457133364
The regression does not display much of a correlation between the data sets.<jupyter_text>Northern Hemisphere - Wind Speed (mph) vs. Latitude Linear Regression<jupyter_code>x_values = pd.to_numeric(northern_df['Lat']).astype(float)
y_values = pd.to_numeric(northern_df['Wind Speed']).astype(float)
(slope, intercept, rvalue, pvalue, stderr) = linregress(x_values, y_values)
regress_values = x_values * slope + intercept
line_eq = "y = " + str(round(slope,2)) + "x + " + str(round(intercept,2))
print(f"Regression line equation is: {line_eq}")
plt.scatter(x_values,y_values)
plt.plot(x_values,regress_values,"r-")
plt.annotate(line_eq,(6,10),fontsize=15,color="red")
plt.xlabel('Latitude')
plt.ylabel('Wind Speed (mph)')
plt.title('Northern Hemisphere - Wind Speed (mph) vs. Latitude Linear Regression')
print(f"The r-squared is: {rvalue}")
print("The regression does not display much of a correlation between the data sets.")
plt.show()<jupyter_output>Regression line equation is: y = 0.07x + 6.96
The r-squared is: 0.2121308497620894
The regression does not display much of a correlation between the data sets.<jupyter_text>Southern Hemisphere - Wind Speed (mph) vs. Latitude Linear Regression<jupyter_code>x_values = pd.to_numeric(southern_df['Lat']).astype(float)
y_values = pd.to_numeric(southern_df['Wind Speed']).astype(float)
(slope, intercept, rvalue, pvalue, stderr) = linregress(x_values, y_values)
regress_values = x_values * slope + intercept
line_eq = "y = " + str(round(slope,2)) + "x + " + str(round(intercept,2))
print(f"Regression line equation is: {line_eq}")
plt.scatter(x_values,y_values)
plt.plot(x_values,regress_values,"r-")
plt.annotate(line_eq,(6,10),fontsize=15,color="red")
plt.xlabel('Latitude')
plt.ylabel('Wind Speed (mph)')
plt.title('Southern Hemisphere - Wind Speed (mph) vs. Latitude Linear Regression')
print(f"The r-squared is: {rvalue}")
print("The regression does not display much of a correlation between the data sets.")
plt.show()<jupyter_output>Regression line equation is: y = -0.17x + 3.69
The r-squared is: -0.3750689191731731
The regression does not display much of a correlation between the data sets.
{'fraction_non_alphanumeric': 0.14856921387507266, 'fraction_numerical': 0.023964860151153025, 'mean_word_length': 6.147737765466298, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 61, 'https://': 1, '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': '17', 'dir': 'jupyter-structured-clean-dedup', 'id': '194694', 'license': 'ADSL', 'n_tokens_mistral': 5918, 'n_tokens_neox': 5443, 'n_words': 1268, 'path': 'WeatherPy/WeatherPy.ipynb', 'repo_name': 'dpalombo97/python-api-challenge', 'size': '15481'}