<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. Three observable trends based on the data:1. As latitude decreases max temperature increases. This can be analyzed on the Latitude vs. Temperature scatter plot as the plot points are at the highest temperature when latitude is closest to zero.2. There is very little correlation between latitude and wind speed. This can be analyzed on the linear regression plots for Northern and Southern Hemisphere as the r-squared value is not near 1.3. Humidity has a very small negative correlation to latitude. This can be analyzed on the linear regression plots for Northern and Southern Hemisphere as the r-squared value is not near 1.<jupyter_code># Dependencies and Setup
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import requests
import time
import json
from scipy.stats import linregress

!pip install citipy
# 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>Requirement already satisfied: citipy in /Users/sarahparzyck/Applications/anaconda3/lib/python3.7/site-packages (0.0.5)
Requirement already satisfied: kdtree>=0.12 in /Users/sarahparzyck/Applications/anaconda3/lib/python3.7/site-packages (from citipy) (0.16)<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(low=-90.000, high=90.000, size=1500)
lngs = np.random.uniform(low=-180.000, high=180.000, 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
base_url = "http://api.openweathermap.org/data/2.5/weather?"
mycity = "Austin"
units = "Imperial"

# Build query URL
query_url = base_url + "appid=" + weather_api_key + "&q=" + mycity + "&units="+ units

mycity_json = requests.get(query_url).json()

print(json.dumps(mycity_json, indent=4, sort_keys=True))
# Set empty lists to hold city data
City = []
Country = []
Date = []
Cloudiness = []
Humidity = []
Latitude = []
Longitude = []
Max_Temp = []
Wind_Speed = []

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

# Loop through each city
for index, city in enumerate(cities):

    # Create search query, make request and store in json
    query_url = base_url + "appid=" + weather_api_key + "&q=" + city + "&units="+ units
    city_json = requests.get(query_url).json()
    
    # Try to grab the city data if they are available in the Weather API
    try:
        City.append(city_json["name"])
        Country.append(city_json["sys"]["country"])
        Date.append(city_json["dt"])
        Cloudiness.append(city_json["clouds"]["all"])
        Humidity.append(city_json["main"]["humidity"])
        Latitude.append(city_json["coord"]["lat"])
        Longitude.append(city_json["coord"]["lon"])
        Max_Temp.append(city_json["main"]["temp_max"])
        Wind_Speed.append(city_json["wind"]["speed"])
        print("Index : {}, City: {} Found ! Collected Weather Data".format(index, city))

    # Handle exceptions for a city that is not available in the Weather API
    except:
        print("Index : {}, City: {} Not found ! Skipping".format(index,city))
        pass
    
print("---------------------------")
print("Data Retrieval Complete")
print("---------------------------")<jupyter_output>Beginning Data Retrieval
---------------------------
Index : 0, City: noblesville Found ! Collected Weather Data
Index : 1, City: cabo san lucas Found ! Collected Weather Data
Index : 2, City: georgetown Found ! Collected Weather Data
Index : 3, City: punta arenas Found ! Collected Weather Data
Index : 4, City: taolanaro Not found ! Skipping
Index : 5, City: ponta do sol Found ! Collected Weather Data
Index : 6, City: den helder Found ! Collected Weather Data
Index : 7, City: touros Found ! Collected Weather Data
Index : 8, City: krasnoselkup Found ! Collected Weather Data
Index : 9, City: belushya guba Not found ! Skipping
Index : 10, City: grand river south east Not found ! Skipping
Index : 11, City: saskylakh Found ! Collected Weather Data
Index : 12, City: akyab Found ! Collected Weather Data
Index : 13, City: mayo Found ! Collected Weather Data
Index : 14, City: cape town Found ! Collected Weather Data
Index : 15, City: ushuaia Found ! Collected Weather Data
Index : 16, City: vill[...]<jupyter_text>Convert Raw Data to DataFrame* Export the city data into a .csv.* Display the DataFrame<jupyter_code># Create new dataframe
weather_df = pd.DataFrame({"City": City,
                           "Country": Country,
                           "Date": Date,
                           "Cloudiness": Cloudiness,
                           "Humidity": Humidity,
                           "Latitude": Latitude,
                           "Longitude": Longitude,
                           "Max Temp": Max_Temp,
                           "Wind Speed": Wind_Speed
})

weather_df
# Save datafram to csv
output_data_file = "output_data/cities.csv"

weather_df.to_csv(output_data_file, index=False, encoding="utf-8")<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># Plot out Latitude versus Temperature scatter plot

plt.scatter(weather_df["Latitude"], weather_df["Max Temp"], marker="o", edgecolors="black")

plt.title("City Latitude vs. Max Temperature 6/19/20")
plt.ylabel("Max Temperature (F)")
plt.xlabel("Latitude")
plt.grid(True)

plt.savefig("Latitude_vs_MaxTemp")

plt.show<jupyter_output><empty_output><jupyter_text>Latitude vs. Humidity Plot<jupyter_code># Plot out Latitude versus Humidity scatter plot
plt.scatter(weather_df["Latitude"], weather_df["Humidity"], marker="o", edgecolors="black")

plt.title("City Latitude vs. Humidity 6/19/20")
plt.ylabel("Humidity (%)")
plt.xlabel("Latitude")
plt.grid(True)

plt.savefig("Latitude_vs_Humidity")

plt.show<jupyter_output><empty_output><jupyter_text>Latitude vs. Cloudiness Plot<jupyter_code># Plot out Latitude versus Cloudiness scatter plot

plt.scatter(weather_df["Latitude"], weather_df["Cloudiness"], marker="o", edgecolors="black")

plt.title("City Latitude vs. Cloudiness 6/19/20")
plt.ylabel("Cloudiness (%)")
plt.xlabel("Latitude")
plt.grid(True)

plt.savefig("Latitude_vs_Cloudiness")

plt.show<jupyter_output><empty_output><jupyter_text>Latitude vs. Wind Speed Plot<jupyter_code># Plot out Latitude versus Wind Speed scatter plot

plt.scatter(weather_df["Latitude"], weather_df["Wind Speed"], marker="o", edgecolors="black")

plt.title("City Latitude vs. Wind Speed 6/19/20")
plt.ylabel("Wind Speed (mph)")
plt.xlabel("Latitude")
plt.grid(True)

plt.savefig("Latitude_vs_WindSpeed")

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
north_df = weather_df.loc[weather_df["Latitude"]>0]
north_df.head()

south_df = weather_df.loc[weather_df["Latitude"]<0]
south_df.head()<jupyter_output><empty_output><jupyter_text>Northern Hemisphere - Max Temp vs. Latitude Linear Regression<jupyter_code># Add the linear regression equation and line to Northern Hemisphere, Max Temp versus Latitude plot.

x_values = north_df['Latitude']
y_values = north_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,40),fontsize=10,color="red")
plt.title("Northern Hemisphere vs. Max Temp 6/19/20")
plt.xlabel('Latitude')
plt.ylabel('Max Temp')

# Print out the r-squared value along with the plot.

print(f"The r-squared is: {rvalue}")
plt.show()<jupyter_output>The r-squared is: -0.7237678731201553<jupyter_text>Southern Hemisphere - Max Temp vs. Latitude Linear Regression<jupyter_code># Add the linear regression equation and line to Southern Hemisphere, Max Temp versus Latitude plot.

x_values = south_df['Latitude']
y_values = south_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,(-55,80),fontsize=10,color="red")
plt.title("Southern Hemisphere vs. Max Temp 6/19/20")
plt.xlabel('Latitude')
plt.ylabel('Max Temp')

# Print out the r-squared value along with the plot.

print(f"The r-squared is: {rvalue}")
plt.show()<jupyter_output>The r-squared is: 0.8149530085407374<jupyter_text>Northern Hemisphere - Humidity (%) vs. Latitude Linear Regression<jupyter_code># Add the linear regression equation and line to Northern Hemisphere, Humidity versus Latitude plot.

x_values = north_df['Latitude']
y_values = north_df['Humidity']
(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,(45,10),fontsize=10,color="red")
plt.title("Northern Hemisphere vs. Humidity 6/19/20")
plt.xlabel('Latitude')
plt.ylabel('Humidity')

# Print out the r-squared value along with the plot.

print(f"The r-squared is: {rvalue}")
plt.show()<jupyter_output>The r-squared is: -0.04126525053232928<jupyter_text>Southern Hemisphere - Humidity (%) vs. Latitude Linear Regression<jupyter_code># Add the linear regression equation and line to Southern Hemisphere, Humidity versus Latitude plot.

x_values = south_df['Latitude']
y_values = south_df['Humidity']
(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,(-55,18),fontsize=10,color="red")
plt.title("Southern Hemisphere vs. Humidity 6/19/20")
plt.xlabel('Latitude')
plt.ylabel('Humidity')

# Print out the r-squared value along with the plot.

print(f"The r-squared is: {rvalue}")
plt.show()<jupyter_output>The r-squared is: -0.03441861411417439<jupyter_text>Northern Hemisphere - Cloudiness (%) vs. Latitude Linear Regression<jupyter_code># Add the linear regression equation and line to Northern Hemisphere, Cloudiness versus Latitude plot.

x_values = north_df['Latitude']
y_values = north_df['Cloudiness']
(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,(7,31),fontsize=10,color="red")
plt.title("Northern Hemisphere vs. Cloudiness 6/19/20")
plt.xlabel('Latitude')
plt.ylabel('Cloudiness')

# Print out the r-squared value along with the plot.

print(f"The r-squared is: {rvalue}")
plt.show()<jupyter_output>The r-squared is: -0.08314678456331<jupyter_text>Southern Hemisphere - Cloudiness (%) vs. Latitude Linear Regression<jupyter_code># Add the linear regression equation and line to Southern Hemisphere, Cloudiness versus Latitude plot.

x_values = south_df['Latitude']
y_values = south_df['Cloudiness']
(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,(-55,68),fontsize=10,color="red")
plt.title("Southern Hemisphere vs. Cloudiness 6/19/20")
plt.xlabel('Latitude')
plt.ylabel('Cloudiness')

# Print out the r-squared value along with the plot.

print(f"The r-squared is: {rvalue}")
plt.show()<jupyter_output>The r-squared is: -0.1301324852838415<jupyter_text>Northern Hemisphere - Wind Speed (mph) vs. Latitude Linear Regression<jupyter_code># Add the linear regression equation and line to Northern Hemisphere, Wind Speed versus Latitude plot.

x_values = north_df['Latitude']
y_values = north_df['Wind Speed']
(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,(40,25),fontsize=10,color="red")
plt.title("Northern Hemisphere vs. Wind Speed 6/19/20")
plt.xlabel('Latitude')
plt.ylabel('Wind Speed')

# Print out the r-squared value along with the plot.

print(f"The r-squared is: {rvalue}")
plt.show()<jupyter_output>The r-squared is: 0.036114267980043746<jupyter_text>Southern Hemisphere - Wind Speed (mph) vs. Latitude Linear Regression<jupyter_code># Add the linear regression equation and line to Southern Hemisphere, Wind Speed versus Latitude plot.

x_values = south_df['Latitude']
y_values = south_df['Wind Speed']
(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,(-55,23),fontsize=10,color="red")
plt.title("Southern Hemisphere vs. Wind Speed 6/19/20")
plt.xlabel('Latitude')
plt.ylabel('Wind Speed')

# Print out the r-squared value along with the plot.

print(f"The r-squared is: {rvalue}")
plt.show()<jupyter_output>The r-squared is: -0.016860176599129216
{'fraction_non_alphanumeric': 0.12827101223882614, 'fraction_numerical': 0.02393670971668132, 'mean_word_length': 5.063960639606396, 'pattern_counts': {'":': 9, '<': 60, '<?xml version=': 0, '>': 61, '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': '17', 'dir': 'jupyter-structured-clean-dedup', 'id': '174590', 'license': 'ADSL', 'n_tokens_mistral': 5389, 'n_tokens_neox': 4909, 'n_words': 1346, 'path': 'WeatherPy/WeatherPy.ipynb', 'repo_name': 'sarahparzyck/python-api-challenge', 'size': '14789'}