<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 seaborn as sns
import pandas as pd
import numpy as np
import requests
import time
import scipy.stats as st

# 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># Building the URL
url = "http://api.openweathermap.org/data/2.5/weather?"
appid = weather_api_key
units = "metric"
url = f"{url}appid={appid}&units={units}&q="

# Creating a list for storing information
city_info = []

# Print begin
print("Beginning Data Retrieval\n-----------------------------")

# Auxiliary counters
record_count = 1
set_count = 1

# For loop
for i, city in enumerate(cities):
        
    # Dividing in sets of 50 as the given example
    if (i % 50 == 0 and i >= 50):
        set_count += 1
        record_count = 0

    # Generating a unique URL for each city
    city_url = url + city

    # Recording the cities, URL and summing the aux counters
    print("Processing Record %s of Set %s | %s" % (record_count, set_count, city))

    record_count += 1

    # API request for each city
    try:
        city_weather = requests.get(city_url).json()

        # Retrieving data
        city_latitute = city_weather["coord"]["lat"]
        city_longitude = city_weather["coord"]["lon"]
        city_max_temperature = city_weather["main"]["temp_max"]
        city_humidity = city_weather["main"]["humidity"]
        city_clouds = city_weather["clouds"]["all"]
        city_wind = city_weather["wind"]["speed"]
        city_country = city_weather["sys"]["country"]
        city_date = city_weather["dt"]

        # Append the retrieved information into city_info
        city_info.append({"City": city, 
                          "Lat": city_latitute, 
                          "Lng": city_longitude, 
                          "Max Temp": city_max_temperature,
                          "Humidity": city_humidity,
                          "Cloudiness": city_clouds,
                          "Wind Speed": city_wind,
                          "Country": city_country,
                          "Date": city_date})

    # Exception for a not found value
    except:
        print("City not found. Skipping...")
        pass
              
# Print ends
print("-----------------------------\nData Retrieval Complete\n-----------------------------")<jupyter_output>Beginning Data Retrieval
-----------------------------
Processing Record 1 of Set 1 | tena
Processing Record 2 of Set 1 | hobart
Processing Record 3 of Set 1 | bredasdorp
Processing Record 4 of Set 1 | inhambane
Processing Record 5 of Set 1 | carnarvon
Processing Record 6 of Set 1 | rikitea
Processing Record 7 of Set 1 | port elizabeth
Processing Record 8 of Set 1 | qaanaaq
Processing Record 9 of Set 1 | busselton
Processing Record 10 of Set 1 | constitucion
Processing Record 11 of Set 1 | mataura
Processing Record 12 of Set 1 | santa maria
Processing Record 13 of Set 1 | oxford
Processing Record 14 of Set 1 | <NAME>
Processing Record 15 of Set 1 | port alfred
Processing Record 16 of Set 1 | punta arenas
Processing Record 17 of Set 1 | namibe
Processing Record 18 of Set 1 | dikson
Processing Record 19 of Set 1 | nguiu
City not found. Skipping...
Processing Record 20 of Set 1 | port hardy
Processing Record 21 of Set 1 | vardo
Processing Record 22 of Set 1 | cape town
Processing Rec[...]<jupyter_text>Convert Raw Data to DataFrame* Export the city data into a .csv.* Display the DataFrame<jupyter_code># Converting the raw data into a data frame
city_info_df = pd.DataFrame(city_info)

# Export data frameinto a csv
city_info_df.to_csv("WeatherPy.csv",encoding="utf-8",index=False)

city_info_df.head()
stats_summary_df = city_info_df.agg(["count", "mean", "std", "min", "max"])
stats_summary_df<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>max_humidity_value = stats_summary_df.iat[2,4]
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># Scatter plot for Latitude vs. Temperature
plt.scatter(city_info_df["Lat"], city_info_df["Max Temp"], marker="o", facecolors="red", edgecolors="black", s=city_info_df["Lat"], alpha=0.75)
plt.show()

#plt.title("Latitude vs. Temperature"
#plt.xlabel("Latitude")
#plt.ylabel("Max Temperature")
#plt.show()

#For some reason, it won't run if I try to add title, xlabel or ylabel.... "SyntaxError: invalid syntax"<jupyter_output><empty_output><jupyter_text>Latitude vs. Humidity Plot<jupyter_code># Scatter plot for Latitude vs. Humidity
plt.scatter(city_info_df["Lat"], city_info_df["Humidity"], marker="o", facecolors="red", edgecolors="black", s=city_info_df["Lat"], alpha=0.75)
plt.show()<jupyter_output><empty_output><jupyter_text>Latitude vs. Cloudiness Plot<jupyter_code># Scatter plot for Latitude vs. Cloudiness
plt.scatter(city_info_df["Lat"], city_info_df["Cloudiness"], marker="o", facecolors="red", edgecolors="black", s=city_info_df["Lat"], alpha=0.75)
plt.show()<jupyter_output><empty_output><jupyter_text>Latitude vs. Wind Speed Plot<jupyter_code># Scatter plot for Latitude vs. Cloudiness
plt.scatter(city_info_df["Lat"], city_info_df["Wind Speed"], marker="o", facecolors="red", edgecolors="black", s=city_info_df["Lat"], alpha=0.75)
plt.show()<jupyter_output><empty_output><jupyter_text>Linear Regression<jupyter_code># Generating different data frames for each Hemisphere
north_hem = city_info_df.loc[city_info_df.Lat > 0]
south_hem = city_info_df.loc[city_info_df.Lat <= 0]<jupyter_output><empty_output><jupyter_text>Northern Hemisphere - Max Temp vs. Latitude Linear Regression<jupyter_code># Linear regression for Latitude vs. Temperature in Northern Hemisphere
x_axis = north_hem.groupby(north_hem["City"])["Lat"].mean()
y_axis = north_hem.groupby(north_hem["City"])["Max Temp"].mean()

slope, int, r, p, std_err = st.linregress(x_axis, y_axis)
      
fit = slope * x_axis + int

plt.scatter(x_axis, y_axis, marker="o", facecolors="red", edgecolors="black")
plt.title("Max Temp vs Lat")
plt.xlabel("Lat")
plt.ylabel("Max Temp")
plt.plot(x_axis,fit,"-")

plt.show()<jupyter_output><empty_output><jupyter_text>Southern Hemisphere - Max Temp vs. Latitude Linear Regression<jupyter_code># Linear regression for Latitude vs. Temperature in Southern Hemisphere
x_axis = south_hem.groupby(south_hem["City"])["Lat"].mean()
y_axis = south_hem.groupby(south_hem["City"])["Max Temp"].mean()

slope, int, r, p, std_err = st.linregress(x_axis, y_axis)
      
fit = slope * x_axis + int

plt.scatter(x_axis, y_axis, marker="o", facecolors="red", edgecolors="black")
plt.title("Max Temp vs Lat")
plt.xlabel("Lat")
plt.ylabel("Max Temp")
plt.plot(x_axis,fit,"-")

plt.show()<jupyter_output><empty_output><jupyter_text>Northern Hemisphere - Humidity (%) vs. Latitude Linear Regression<jupyter_code># Linear regression for Latitude vs. Humidity in Northern Hemisphere
x_axis = north_hem.groupby(north_hem["City"])["Lat"].mean()
y_axis = north_hem.groupby(north_hem["City"])["Humidity"].mean()

slope, int, r, p, std_err = st.linregress(x_axis, y_axis)
      
fit = slope * x_axis + int

plt.scatter(x_axis, y_axis, marker="o", facecolors="red", edgecolors="black")
plt.title("Humidity vs Lat")
plt.xlabel("Lat")
plt.ylabel("Humidity")
plt.plot(x_axis,fit,"-")

plt.show()<jupyter_output><empty_output><jupyter_text>Southern Hemisphere - Humidity (%) vs. Latitude Linear Regression<jupyter_code># Linear regression for Latitude vs. Humidity in Southern Hemisphere
x_axis = south_hem.groupby(south_hem["City"])["Lat"].mean()
y_axis = south_hem.groupby(south_hem["City"])["Humidity"].mean()

slope, int, r, p, std_err = st.linregress(x_axis, y_axis)
      
fit = slope * x_axis + int

plt.scatter(x_axis, y_axis, marker="o", facecolors="red", edgecolors="black")
plt.title("Humidity vs Lat")
plt.xlabel("Lat")
plt.ylabel("Humidity")
plt.plot(x_axis,fit,"-")

plt.show()<jupyter_output><empty_output><jupyter_text>Northern Hemisphere - Cloudiness (%) vs. Latitude Linear Regression<jupyter_code># Linear regression for Latitude vs. Cloudiness in Northern Hemisphere
x_axis = north_hem.groupby(north_hem["City"])["Lat"].mean()
y_axis = north_hem.groupby(north_hem["City"])["Cloudiness"].mean()

slope, int, r, p, std_err = st.linregress(x_axis, y_axis)
      
fit = slope * x_axis + int

plt.scatter(x_axis, y_axis, marker="o", facecolors="red", edgecolors="black")
plt.title("Cloudiness vs Lat")
plt.xlabel("Lat")
plt.ylabel("Cloudiness")
plt.plot(x_axis,fit,"-")

plt.show()<jupyter_output><empty_output><jupyter_text>Southern Hemisphere - Cloudiness (%) vs. Latitude Linear Regression<jupyter_code># Linear regression for Latitude vs. Cloudiness in Southern Hemisphere
x_axis = south_hem.groupby(south_hem["City"])["Lat"].mean()
y_axis = south_hem.groupby(south_hem["City"])["Cloudiness"].mean()

slope, int, r, p, std_err = st.linregress(x_axis, y_axis)
      
fit = slope * x_axis + int

plt.scatter(x_axis, y_axis, marker="o", facecolors="red", edgecolors="black")
plt.title("Cloudiness vs Lat")
plt.xlabel("Lat")
plt.ylabel("Cloudiness")
plt.plot(x_axis,fit,"-")

plt.show()<jupyter_output><empty_output><jupyter_text>Northern Hemisphere - Wind Speed (mph) vs. Latitude Linear Regression<jupyter_code># Linear regression for Latitude vs. Wind Speed in Northern Hemisphere
x_axis = north_hem.groupby(north_hem["City"])["Lat"].mean()
y_axis = north_hem.groupby(north_hem["City"])["Wind Speed"].mean()

slope, int, r, p, std_err = st.linregress(x_axis, y_axis)
      
fit = slope * x_axis + int

plt.scatter(x_axis, y_axis, marker="o", facecolors="red", edgecolors="black")
plt.title("Wind Speed vs Lat")
plt.xlabel("Lat")
plt.ylabel("Wind Speed")
plt.plot(x_axis,fit,"-")

plt.show()<jupyter_output><empty_output><jupyter_text>Southern Hemisphere - Wind Speed (mph) vs. Latitude Linear Regression<jupyter_code># Linear regression for Latitude vs. Wind Speed in Southern Hemisphere
x_axis = south_hem.groupby(south_hem["City"])["Lat"].mean()
y_axis = south_hem.groupby(south_hem["City"])["Wind Speed"].mean()

slope, int, r, p, std_err = st.linregress(x_axis, y_axis)
      
fit = slope * x_axis + int

plt.scatter(x_axis, y_axis, marker="o", facecolors="red", edgecolors="black")
plt.title("Wind Speed vs Lat")
plt.xlabel("Lat")
plt.ylabel("Wind Speed")
plt.plot(x_axis,fit,"-")

plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1341442953020134, 'fraction_numerical': 0.009899328859060403, 'mean_word_length': 4.695652173913044, 'pattern_counts': {'":': 9, '<': 74, '<?xml version=': 0, '>': 77, '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': '285679', 'license': 'ADSL', 'n_tokens_mistral': 4260, 'n_tokens_neox': 3969, 'n_words': 1074, 'path': 'starter_code/WeatherPy.ipynb', 'repo_name': 'MauCFD/What-s-the-Weather-Like-', 'size': '11925'}