<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 json
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
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>url = "http://api.openweathermap.org/data/2.5/weather?"
units = "metric"

query_url = f"{url}appid={weather_api_key}&units={units}&q="
lat = []
lon = []
temp_max = []
humidity = []
cloud = []
wind = []
dt = []
city_name = []
set_count = 1
record_count = 1
print("Beginning Data Retrieval")
print("-----------------------------------")
for index, city in enumerate(cities):
    if(index % 50 == 0 and index >=50):
        set_count += 1
        record_count = 0
    print(f"Processing Record {record_count} of Set {set_count} | {city}")
    record_count += 1
    try:
        city_query = query_url + city
        response = requests.get(city_query).json()

        city_lat = response['coord']['lat']
        city_lon = response['coord']['lon']
        city_max_temp = response['main']['temp_max']
        city_humidity = response['main']['humidity']
        city_cloud = response['clouds']['all']
        city_wind_speed = response['wind']['speed']
        city_date = response['dt']

        lat.append(city_lat)
        lon.append(city_lon)
        temp_max.append(city_max_temp)
        humidity.append(city_humidity)
        cloud.append(city_cloud)
        wind.append(city_wind_speed)
        dt.append(city_date)
        city_name.append(city)
        
    except:
        print("City not found")<jupyter_output>Beginning Data Retrieval
-----------------------------------
Processing Record 1 of Set 1 | hermanus
Processing Record 2 of Set 1 | deshnok
Processing Record 3 of Set 1 | tiksi
Processing Record 4 of Set 1 | la presa
Processing Record 5 of Set 1 | ballangen
Processing Record 6 of Set 1 | vestmanna
Processing Record 7 of Set 1 | khatanga
Processing Record 8 of Set 1 | mahebourg
Processing Record 9 of Set 1 | busselton
Processing Record 10 of Set 1 | kapaa
Processing Record 11 of Set 1 | taolanaro
City not found
Processing Record 12 of Set 1 | keshorai patan
Processing Record 13 of Set 1 | cape town
Processing Record 14 of Set 1 | kusa
Processing Record 15 of Set 1 | vieques
Processing Record 16 of Set 1 | baie-saint-paul
Processing Record 17 of Set 1 | asosa
Processing Record 18 of Set 1 | albany
Processing Record 19 of Set 1 | san quintin
Processing Record 20 of Set 1 | manokwari
Processing Record 21 of Set 1 | carndonagh
Processing Record 22 of Set 1 | torbay
Processing Record 23 of S[...]<jupyter_text>Convert Raw Data to DataFrame* Export the city data into a .csv.* Display the DataFrame<jupyter_code>weather_data = pd.DataFrame({"City": city_name, "Lat": lat, "Lng": lon, "Max Temp": temp_max, 
                "Humidity": humidity, "Cloudiness": cloud, "Wind Speed": wind,
                "Date": dt
               })

weather_data.to_csv("cities.csv")
weather_data

weather_data.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>high_humid = weather_data.loc[(weather_data["Humidity"] > 100)]
high_humid
#  Get the indices of cities that have humidity over 100%.

# 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".<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>weather_data.plot(kind='scatter', x='Lat', y='Max Temp')
plt.title("Maximum Temperature vs. Latitude")

plt.grid()<jupyter_output><empty_output><jupyter_text>Latitude vs. Humidity Plot<jupyter_code>weather_data.plot(kind='scatter', x='Lat', y='Humidity')
plt.title("Humidity vs. Latitude")

plt.grid()<jupyter_output><empty_output><jupyter_text>Latitude vs. Cloudiness Plot<jupyter_code>weather_data.plot(kind='scatter', x='Lat', y='Cloudiness')
plt.title("Cloudiness vs. Latitude")

plt.grid()<jupyter_output><empty_output><jupyter_text>Latitude vs. Wind Speed Plot<jupyter_code>weather_data.plot(kind='scatter', x='Lat', y='Wind Speed')
plt.title("Wind Speed vs. Latitude")

plt.grid()<jupyter_output><empty_output><jupyter_text>Linear Regression<jupyter_code>def linreg(x_values, y_values, title, coordinates):
    (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,coordinates,fontsize=15,color="red")
    plt.xlabel('Latitude')
    plt.ylabel(title)
    print(f"The r-squared is: {rvalue}")
    plt.show()<jupyter_output><empty_output><jupyter_text>Northern Hemisphere - Max Temp vs. Latitude Linear Regression<jupyter_code>north_city = weather_data.loc[(weather_data["Lat"] >= 0)]

north_city.plot(kind='scatter', x='Lat', y='Max Temp')
plt.title("Maximum Temperature vs. Latitude for Northern Hemisphere")
plt.grid()
x_values = north_city["Lat"]

y_values = north_city["Max Temp"]

linreg(north_city["Lat"],north_city["Max Temp"], "Maximum Temperature", (0,-5))<jupyter_output>The r-squared is: -0.8886084205134966<jupyter_text>Southern Hemisphere - Max Temp vs. Latitude Linear Regression<jupyter_code>south_city = weather_data.loc[(weather_data["Lat"] < 0)]

south_city.plot(kind='scatter', x='Lat', y='Max Temp')
plt.title("Maximum Temperature vs. Latitude for Southern Hemisphere")
plt.grid()
x_values = south_city["Lat"]

y_values = south_city["Max Temp"]

linreg(south_city["Lat"],south_city["Max Temp"], "Maximum Temperature", (-55,35))<jupyter_output>The r-squared is: 0.6667730531039028<jupyter_text>Northern Hemisphere - Humidity (%) vs. Latitude Linear Regression<jupyter_code>north_city.plot(kind='scatter', x='Lat', y='Max Temp')
plt.title("Humidity vs. Latitude for Northern Hemisphere")
plt.grid()
x_values = north_city["Lat"]

y_values = north_city["Humidity"]

linreg(north_city["Lat"],north_city["Humidity"], "Humidity", (0,-10))<jupyter_output>The r-squared is: 0.2385908831689431<jupyter_text>Southern Hemisphere - Humidity (%) vs. Latitude Linear Regression<jupyter_code>south_city.plot(kind='scatter', x='Lat', y='Max Temp')
plt.title("Humidity vs. Latitude for Southern Hemisphere")
plt.grid()
x_values = south_city["Lat"]

y_values = south_city["Humidity"]

linreg(south_city["Lat"],south_city["Humidity"], "Humidity", (-25,5))<jupyter_output>The r-squared is: -0.0841516568813803<jupyter_text>Northern Hemisphere - Cloudiness (%) vs. Latitude Linear Regression<jupyter_code>north_city.plot(kind='scatter', x='Lat', y='Max Temp')
plt.title("Cloudiness vs. Latitude for Northern Hemisphere")
plt.grid()
x_values = north_city["Lat"]

y_values = north_city["Cloudiness"]

linreg(north_city["Lat"],north_city["Cloudiness"], "Cloudiness", (0,-10))<jupyter_output>The r-squared is: 0.2014816417197162<jupyter_text>Southern Hemisphere - Cloudiness (%) vs. Latitude Linear Regression<jupyter_code>south_city.plot(kind='scatter', x='Lat', y='Max Temp')
plt.title("Cloudiness vs. Latitude for Southern Hemisphere")
plt.grid()
x_values = south_city["Lat"]

y_values = south_city["Cloudiness"]

linreg(south_city["Lat"],south_city["Cloudiness"], "Cloudiness", (-55,50))<jupyter_output>The r-squared is: 0.07588281083842631<jupyter_text>Northern Hemisphere - Wind Speed (mph) vs. Latitude Linear Regression<jupyter_code>north_city.plot(kind='scatter', x='Lat', y='Max Temp')
plt.title("Wind Speed vs. Latitude for Northern Hemisphere")
plt.grid()
x_values = north_city["Lat"]

y_values = north_city["Wind Speed"]

linreg(north_city["Lat"],north_city["Wind Speed"], "Wind Speed", (0,-10))<jupyter_output>The r-squared is: 0.16245953734819996<jupyter_text>Southern Hemisphere - Wind Speed (mph) vs. Latitude Linear Regression<jupyter_code>south_city.plot(kind='scatter', x='Lat', y='Max Temp')
plt.title("Wind Speed vs. Latitude for Southern Hemisphere")
plt.grid()
x_values = south_city["Lat"]

y_values = south_city["Wind Speed"]

linreg(south_city["Lat"],south_city["Wind Speed"], "Wind Speed", (-55,30))<jupyter_output>The r-squared is: -0.1903157843470486
{'fraction_non_alphanumeric': 0.13013838013838014, 'fraction_numerical': 0.028184778184778186, 'mean_word_length': 5.213021491782554, 'pattern_counts': {'":': 8, '<': 65, '<?xml version=': 0, '>': 69, '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': '222936', 'license': 'ADSL', 'n_tokens_mistral': 3628, 'n_tokens_neox': 3256, 'n_words': 873, 'path': 'WeatherPy/WeatherPy.ipynb', 'repo_name': 'shellymnixon/python-api-challenge', 'size': '9828'}