<jupyter_start><jupyter_text>WeatherPy----<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(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 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* Performed a weather check on each city using a series of successive API calls.* Included a print log of each city as it's being 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 = []
country = []
lat = []
long = []
temperatures = []
max_temp = []
humidity = []
cloudiness = []
wind_speed = []
date = []

counter = 1

for city in cities: 
       
    try: 
        response = requests.get(f"{url}&q={city}").json()
        city_name.append(response['name'])
        country.append(response["sys"]["country"])
        lat.append(response['coord']['lat'])
        long.append(response['coord']['lon'])
        temperatures.append(response['main']['temp'])
        max_temp.append(response["main"]["temp_max"])
        humidity.append(response['main']['humidity'])
        cloudiness.append(response['clouds']['all'])
        wind_speed.append(response['wind']['speed'])
        date.append(response['dt'])
        print(f'City number {counter} complete. Added {city}')
        counter += 1

    except:
        print("City not found. Skipping...")
    continue
        
print('----------------------------------------------')
print('------------Data Retrieval Complete-----------')<jupyter_output>City number 1 complete. Added hithadhoo
City not found. Skipping...
City number 2 complete. Added pemangkat
City number 3 complete. Added north bend
City number 4 complete. Added porto walter
City number 5 complete. Added albany
City not found. Skipping...
City number 6 complete. Added cape town
City number 7 complete. Added ushtobe
City number 8 complete. Added sao paulo de olivenca
City number 9 complete. Added georgetown
City number 10 complete. Added vaini
City number 11 complete. Added punta arenas
City not found. Skipping...
City number 12 complete. Added sterling
City not found. Skipping...
City number 13 complete. Added taungdwingyi
City number 14 complete. Added macau
City number 15 complete. Added millinocket
City number 16 complete. Added mount isa
City number 17 complete. Added port blair
City number 18 complete. Added torbay
City not found. Skipping...
City number 19 complete. Added upernavik
City number 20 complete. Added new norfolk
City number 21 complete. Added hilo
Ci[...]<jupyter_text>Convert Raw Data to DataFrame* Exported the city data into a .csv.* Displayed the DataFrame<jupyter_code>#create new df
weather_py = pd.DataFrame ({
    "city": city_name,
    "lat": lat,
    "lng": long,
    'max_temp': max_temp,
    'humidity': humidity,
    'cloudiness': cloudiness,
    'wind_speed': wind_speed,
    'country': country,
    'date': date
})
#save df as .csv to output_data folder
weather_py.to_csv("../output_data/cities.csv")
weather_py.head()
#verify final count of data
weather_py.count()<jupyter_output><empty_output><jupyter_text>Inspect the data and remove the cities where the humidity > 100%.----<jupyter_code>#check humidity % for any over 100. If none, move on. (There are none, moving on...)
humidity_check = weather_py.loc[:, 'humidity'].unique()
humidity_check<jupyter_output><empty_output><jupyter_text>Plotting the Data  Latitude vs. Temperature Plot<jupyter_code>#create scatterplot
ax1 = weather_py.plot.scatter(x='lat', y='max_temp',edgecolors='purple', c='black')
plt.grid(b=True, which='major', axis='both', linestyle="-", color='lightgrey')
plt.title('Latitude vs. Temperature (8/15/20)', size=12)
plt.xlabel('Latitude', size=12)
plt.ylabel('Temperature', size=12)
plt.savefig("../output_data/lat_temp.png")
plt.show()<jupyter_output><empty_output><jupyter_text>Latitude vs. Temp Breakdown:This is showing that the cities that lie between 0 and about 40 degrees latitude are warmest. On the flip side, there are some cities that are both warm and cool from 0 to -20. I also see that from -60 to 0 there is a positive correlation, with temps increasing as latitude nears 0. There is also a negative correlation from 0 to 80, temps decrease as cities move further away from 0.   Latitude vs. Humidity Plot<jupyter_code>#create scatterplot
ax1 = weather_py.plot.scatter(x='lat', y='humidity',edgecolors='black', c='red')
plt.grid(b=True, which='major', axis='both', linestyle="-", color='lightgrey')
plt.title('Latitude vs. Humidity (8/15/20)', size=12)
plt.xlabel('Latitude', size=12)
plt.ylabel('Humidity', size=12)
plt.savefig("../output_data/lat_humidity.png")
plt.show()<jupyter_output><empty_output><jupyter_text>Lat vs. Humidity Breakdown:There isn't a whole lot of correlation here. The northern hemisphere humidity is all over the place. However, the cities that are between 0 and 20 latitude do seem to have a higher percentage of humidity. The Southern Hemisphere doesn't show too many cities with humidity below 20%. From 0 to 20 latitude, humidity is bounded between 60 and 100. When latitude is below 0 it's sparse. Overall, there is not a strong correlation.  Latitude vs. Cloudiness Plot<jupyter_code>#create scatterplot
ax1 = weather_py.plot.scatter(x='lat', y='cloudiness',edgecolors='teal', c='blue')
plt.grid(b=True, which='major', axis='both', linestyle="-", color='lightgrey')
plt.title('Latitude vs. Cloudiness (8/15/20)', size=12)
plt.xlabel('Latitude', size=12)
plt.ylabel('Cloudiness', size=12)
plt.savefig("../output_data/lat_cloudiness.png")
plt.show()<jupyter_output><empty_output><jupyter_text>Latitude vs. Cloudiness breakdown:This is pretty scattered. It looks like the closer you are to the equater the more scattered the cloudiness. However, there are also some extremes. From -20 to -40ish and 20-75ish latitude, there are trends of clouds with 0%. However, there are also some trends of 100% cloudiness in the 20 - 75 range. Overall, there is no correlation between the two.  Latitude vs. Wind Speed Plot<jupyter_code>#create scatterplot
ax1 = weather_py.plot.scatter(x='lat', y='wind_speed',edgecolors='black', c='grey')
plt.grid(b=True, which='major', axis='both', linestyle="-", color='lightgrey')
plt.title('Latitude vs. Wind Speed (8/15/20)', size=12)
plt.xlabel('Latitude', size=12)
plt.ylabel('Wind Speed', size=12)
plt.savefig("../output_data/lat_wind.png")
plt.show()<jupyter_output><empty_output><jupyter_text>Latitude vs. Wind Speed Breakdown:It appears as though the wind speed is mostly low. Latitude does not appear to make a difference in wind speed as majority of it is fairly similar. Again, I would say that there is no correlation between the two.  Linear Regression<jupyter_code># OPTIONAL: Create a function to create Linear Regression plots
#create df for cities in northern hemisphere
north_hem = weather_py[weather_py.lat > 0]
north_hem
#create df for cities in southern hemisphere
south_hem = weather_py[weather_py.lat < 0]
south_hem<jupyter_output><empty_output><jupyter_text>Northern Hemisphere - Max Temp vs. Latitude Linear Regression<jupyter_code>#create scatter plot using hemisphere dataframe
x_values = north_hem['lat']
y_values = north_hem['max_temp']
plt.scatter(x_values, y_values)
plt.title('Northern Hemisphere - Max Temp vs. Latitude Linear Regression (8/15/20)', size=12)
plt.xlabel('Latitude', size=12)
plt.ylabel('Max Temp', size=12)


## add a linear regression equation
(slope, intercept, rvalue, pvalue, stderr) = linregress(x_values, y_values)

## taking the equation from the line above, and calculating the points along the line
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,35), fontsize = 15, color="black")

print(f'The r-squared is: {rvalue}')
plt.savefig("../output_data/reg_north_lat_temp.png")
plt.show()<jupyter_output>The r-squared is: -0.7342722721715016<jupyter_text>Northern Hemisphere - Temp vs. Lat: From 0-20 latitude, as values increase, temps increase. As soon as latitude starts to increase, temperatures begin to decrease. There is a negative correlation and r-squared is good but not great.    Southern Hemisphere - Max Temp vs. Latitude Linear Regression<jupyter_code>#create scatter plot using hemisphere dataframe
x_values = south_hem['lat']
y_values = south_hem['max_temp']
plt.scatter(x_values, y_values)
plt.title('Southern Hemisphere - Max Temp vs. Latitude Linear Regression (8/15/20)', size=12)
plt.xlabel('Latitude', size=12)
plt.ylabel('Max Temp', size=12)

## add a linear regression equation
(slope, intercept, rvalue, pvalue, stderr) = linregress(x_values, y_values)

## taking the equation from the line above, and calculating the points along the line
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, (-20,35), fontsize = 10, color="black")
plt.savefig("../output_data/reg_south_lat_temp.png")
print(f'The r-squared is: {rvalue}')
plt.show()<jupyter_output>The r-squared is: 0.7328741050143442<jupyter_text>The fit of the linear regression is good but not great. There is a positive relationship. As latitue increases so do tempereatures.   Northern Hemisphere - Humidity (%) vs. Latitude Linear Regression<jupyter_code>#create scatter plot using hemisphere dataframe
x_values = north_hem['lat']
y_values = north_hem['humidity']
plt.scatter(x_values, y_values)
plt.title('Northern Hemisphere - Humidity vs. Latitude Linear Regression (8/15/20)', size=12)
plt.xlabel('Latitude', size=12)
plt.ylabel('Humidity', size=12)

## add a linear regression equation
(slope, intercept, rvalue, pvalue, stderr) = linregress(x_values, y_values)

## taking the equation from the line above, and calculating the points along the line
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, (48,10), fontsize = 10, color="black")
plt.savefig("../output_data/reg_north_lat_humidity.png")
print(f'The r-squared is: {rvalue}')
plt.show()<jupyter_output>The r-squared is: -0.038296452243842455<jupyter_text>There is no correclation between humidity and latitude. The low value of r-squared implies that linear regression does not fit the data well.    Southern Hemisphere - Humidity (%) vs. Latitude Linear Regression<jupyter_code>#create scatter plot using hemisphere dataframe
x_values = south_hem['lat']
y_values = south_hem['humidity']
plt.scatter(x_values, y_values)
plt.title('Southern Hemisphere - Humidity vs. Latitude Linear Regression (8/15/20)', size=12)
plt.xlabel('Latitude', size=12)
plt.ylabel('Humidity', size=12)

## add a linear regression equation
(slope, intercept, rvalue, pvalue, stderr) = linregress(x_values, y_values)

## taking the equation from the line above, and calculating the points along the line
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, (-50,20), fontsize = 10, color="black")
plt.savefig("../output_data/reg_south_lat_humidity.png")
print(f'The r-squared is: {rvalue}')
plt.show()<jupyter_output>The r-squared is: 0.025626784535894453<jupyter_text>Again, there is no correclation between humidity and latitude. The low value of r-squared implies that linear regression does not fit the data well.    Northern Hemisphere - Cloudiness (%) vs. Latitude Linear Regression<jupyter_code>#create scatter plot using hemisphere dataframe
x_values = north_hem['lat']
y_values = north_hem['cloudiness']
plt.scatter(x_values, y_values)
plt.title('Northern Hemisphere - Cloudiness vs. Latitude Linear Regression (8/15/20)', size=12)
plt.xlabel('Latitude', size=12)
plt.ylabel('Cloudiness', size=12)

## add a linear regression equation
(slope, intercept, rvalue, pvalue, stderr) = linregress(x_values, y_values)

## taking the equation from the line above, and calculating the points along the line
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,-1), fontsize = 10, color="black")
plt.savefig("../output_data/reg_north_lat_cloud.png")
print(f'The r-squared is: {rvalue}')
plt.show()<jupyter_output>The r-squared is: 0.03237322065580149<jupyter_text>Again, there is no correclation between cloudiness and latitude. The low value of r-squared implies that linear regression does not fit the data well.    Southern Hemisphere - Cloudiness (%) vs. Latitude Linear Regression<jupyter_code>#create scatter plot using hemisphere dataframe
x_values = south_hem['lat']
y_values = south_hem['cloudiness']
plt.scatter(x_values, y_values)
plt.title('Southern Hemisphere - Cloudiness vs. Latitude Linear Regression (8/15/20)', size=12)
plt.xlabel('Latitude', size=12)
plt.ylabel('Cloudiness', size=12)

## add a linear regression equation
(slope, intercept, rvalue, pvalue, stderr) = linregress(x_values, y_values)

## taking the equation from the line above, and calculating the points along the line
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,15), fontsize = 10, color="black")
plt.savefig("../output_data/reg_south_lat_cloud.png")
print(f'The r-squared is: {rvalue}')
plt.show()<jupyter_output>The r-squared is: 0.06678283495968489<jupyter_text>Again, there is no correclation between cloudiness and latitude. The low value of r-squared implies that linear regression does not fit the data well.    Northern Hemisphere - Wind Speed (mph) vs. Latitude Linear Regression<jupyter_code>#create scatter plot using hemisphere dataframe
x_values = north_hem['lat']
y_values = north_hem['wind_speed']
plt.scatter(x_values, y_values)
plt.title('Northern Hemisphere - Wind Speed vs. Latitude Linear Regression (8/15/20)', size=12)
plt.xlabel('Latitude', size=12)
plt.ylabel('Wind Speed', size=12)

## add a linear regression equation
(slope, intercept, rvalue, pvalue, stderr) = linregress(x_values, y_values)

## taking the equation from the line above, and calculating the points along the line
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,-1), fontsize = 10, color="black")
plt.savefig("../output_data/reg_north_lat_wind.png")
print(f'The r-squared is: {rvalue}')
plt.show()<jupyter_output>The r-squared is: 0.11127151085511808<jupyter_text>In regards to wind speed and latitude, there still is no correlation. The low value of r-squared implies that linear regression does not fit the data well despite the appearance of the scatter plot.   Southern Hemisphere - Wind Speed (mph) vs. Latitude Linear Regression<jupyter_code>#create scatter plot using hemisphere dataframe
x_values = south_hem['lat']
y_values = south_hem['wind_speed']
plt.scatter(x_values, y_values)
plt.title('Southern Hemisphere - Wind Speed vs. Latitude Linear Regression (8/15/20)', size=12)
plt.xlabel('Latitude', size=12)
plt.ylabel('Wind Speed', size=12)

## add a linear regression equation
(slope, intercept, rvalue, pvalue, stderr) = linregress(x_values, y_values)

## taking the equation from the line above, and calculating the points along the line
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, (-20,30), fontsize = 10, color="black")
plt.savefig("../output_data/reg_south_lat_wind.png")

print(f'The r-squared is: {rvalue}')
plt.show()<jupyter_output>The r-squared is: -0.3705135716323963
{'fraction_non_alphanumeric': 0.12294512618661728, 'fraction_numerical': 0.026279231303542486, 'mean_word_length': 5.3471711976487875, 'pattern_counts': {'":': 3, '<': 65, '<?xml version=': 0, '>': 66, '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': '560398', 'license': 'ADSL', 'n_tokens_mistral': 6201, 'n_tokens_neox': 5579, 'n_words': 1728, 'path': 'weather_py/WeatherPy.ipynb', 'repo_name': 'gamem001/python-api-challenge', 'size': '17276'}