<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
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(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>url = "http://api.openweathermap.org/data/2.5/weather?units=Imperial&APPID=" + weather_api_key
city_name = []
cloudiness = []
country = []
date = []
humidity = []
lat = []
lng = []
max_temp = []
wind_speed = []
# Start the call counter
record = 1
x =1

# Log file print statement
print(f"Beginning Data Retrieval")
print(f"-------------------------------")
#Loop through the cities in the city list
for city in cities:
    # Try statement to append calls where value is found
    # Not all calls return data as OpenWeatherMap will not have have records in all the cities generated by CityPy module
    try:
        response = requests.get(f"{url}&q={city}").json()
        city_name.append(response["name"])
        cloudiness.append(response["clouds"]["all"])
        country.append(response["sys"]["country"])
        date.append(response["dt"])
        humidity.append(response["main"]["humidity"])
        max_temp.append(response["main"]["temp_max"])
        lat.append(response["coord"]["lat"])
        lng.append(response["coord"]["lon"])
        wind_speed.append(response["wind"]["speed"])
        city_record = response["name"]
        print(f"Processing Record {record} of set {x} | {city_record}")
        #print(f"{url}&q={city}")
        # Increase counter by one
        record= record + 1
        # Wait a second in loop to not over exceed rate limit of API
        time.sleep(1.01)
    # If no record found "skip" to next call
    except:
        print("City not found. Skipping...")
    continue
print("------------------------------\nData Retrieval Complete\n------------------------------")
print(response)<jupyter_output>Beginning Data Retrieval
-------------------------------
Processing Record 1 of set 1 | Rikitea
Processing Record 2 of set 1 | Kavieng
Processing Record 3 of set 1 | Luderitz
Processing Record 4 of set 1 | Hermanus
Processing Record 5 of set 1 | Hobart
Processing Record 6 of set 1 | Afyonkarahisar
Processing Record 7 of set 1 | Kavaratti
Processing Record 8 of set 1 | Ushuaia
Processing Record 9 of set 1 | Puerto Ayora
City not found. Skipping...
Processing Record 10 of set 1 | Kruisfontein
Processing Record 11 of set 1 | Macapa
Processing Record 12 of set 1 | <NAME>
Processing Record 13 of set 1 | Avarua
Processing Record 14 of set 1 | Provideniya
Processing Record 15 of set 1 | Kapaa
Processing Record 16 of set 1 | Dareda
Processing Record 17 of set 1 | Busselton
Processing Record 18 of set 1 | Miri
Processing Record 19 of set 1 | Hithadhoo
Processing Record 20 of set 1 | Freeport
Processing Record 21 of set 1 | Marzuq
Processing Record 22 of set 1 | Oranjemund
Processing Reco[...]<jupyter_text>Convert Raw Data to DataFrame* Export the city data into a .csv.* Display the DataFrame<jupyter_code>weather_dict = {
    "City_ID": city_name,
    "Cloudiness":cloudiness,
    "Country":country,
    "Date":date,
    "Humidity": humidity,
    "Lat":lat,
    "Lng":lng,
    "Max Temp": max_temp,
    "Wind Speed":wind_speed
}
weather_data = pd.DataFrame(weather_dict)
weather_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>plt.scatter(weather_data["Lat"],weather_data["Max Temp"], marker= "o")
plt.title("City Latitude vs. Max Temperature(05/28/19)")
plt.xlabel("Latitude")
plt.ylabel("Max Temperature(F)")
plt.grid(True)
plt.savefig("City Latitude vs. Max Temperature.png")
plt.show()<jupyter_output><empty_output><jupyter_text>Analysis The graph is showing relationship between city latitude and max temperature.There is no dramatic increase from latitude -60 to 0, but it continously drops as latitude goes north. cities with highest max temperature are around latitude 0.  Latitude vs. Humidity Plot<jupyter_code>plt.scatter(weather_data["Lat"],weather_data["Humidity"], marker= "o")
plt.title("City Latitude vs. Humidity(05/28/19)")
plt.xlabel("Latitude")
plt.ylabel("Humidity(%)")
plt.grid(True)
plt.savefig("City Latitude vs. Humidity.png")
plt.show()<jupyter_output><empty_output><jupyter_text>Analysis The graph is showing relationship between city latitude and Humidity.Cities with highest max humidity are around latitude 60.  Latitude vs. Cloudiness Plot<jupyter_code>plt.scatter(weather_data["Lat"],weather_data["Cloudiness"], marker= "o")
plt.title("City Latitude vs. Cloudiness(08/22/19)")
plt.xlabel("Latitude")
plt.ylabel("Cloudiness(%)")
plt.grid(True)
plt.savefig("City Latitude vs. Cloudiness.png")
plt.show()<jupyter_output><empty_output><jupyter_text>Analysis The graph is showing relationship between city latitude and Cloudiness.Cities with highest max cloudiness are between latitude 40 to 70.  Latitude vs. Wind Speed Plot<jupyter_code>plt.scatter(weather_data["Lat"],weather_data["Wind Speed"], marker= "o")
plt.title("City Latitude vs. Wind Speed(05/28/19)")
plt.xlabel("Latitude")
plt.ylabel("WInd Speed(mph)")
plt.grid(True)
plt.savefig("City Latitude vs. Wind Speed.png")
plt.show()<jupyter_output><empty_output><jupyter_text>Analysis The graph is showing relationship between city latitude and Wind speed.Cities with highest max cloudiness are between latitude 40 to 70.  Linear Regression<jupyter_code># OPTIONAL: Create a function to create Linear Regression plots

# Create Northern and Southern Hemisphere DataFrames<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11738759248719408, 'fraction_numerical': 0.020631758679567444, 'mean_word_length': 4.373853211009174, 'pattern_counts': {'":': 9, '<': 37, '<?xml version=': 0, '>': 37, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '581254', 'license': 'ADSL', 'n_tokens_mistral': 2322, 'n_tokens_neox': 2129, 'n_words': 735, 'path': 'starter_code/WeatherPy.ipynb', 'repo_name': 'pbhoomika888/Python-API_Challange', 'size': '7035'}