<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 urllib.parse

# 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>data ={
    'City': [],
    'Lat': [],
    'Lng': [],
    'Max Temp': [],
    'Humidity': [],
    'Cloudiness': [],
    'Wind Speed': [],
    'Country': [],
    'Date': []
}
for i, city in enumerate(cities):
    print(f'{i+1} of 620 Requesting data for {city}',end = '')
    url = f'http://api.openweathermap.org/data/2.5/weather?q={city}&units=imperial&appid={weather_api_key}'
    response = requests.get(url).json()
    try : 
        data['Lat'].append(response['coord']['lat'])
        data['Lng'].append(response['coord']['lon'])
        data['Max Temp'].append(response['main']['temp_max'])
        data['Humidity'].append(response['main']['humidity'])
        data['Cloudiness'].append(response['clouds']['all'])
        data['Wind Speed'].append(response['wind']['speed'])
        data['Country'].append(response['sys']['country'])
        data['Date'].append(response['dt'])
        data['City'].append(city)
        print(' | DONE')
    except : 
        print(' | Not found')
   
cities_df = pd.DataFrame.from_dict(data)<jupyter_output>1 of 620 Requesting data for tahe | DONE
2 of 620 Requesting data for kapaa | DONE
3 of 620 Requesting data for east london | DONE
4 of 620 Requesting data for castro | DONE
5 of 620 Requesting data for enumclaw | DONE
6 of 620 Requesting data for monte alegre | DONE
7 of 620 Requesting data for rikitea | DONE
8 of 620 Requesting data for valley city | DONE
9 of 620 Requesting data for sangar | DONE
10 of 620 Requesting data for louisbourg | Not found
11 of 620 Requesting data for cherskiy | DONE
12 of 620 Requesting data for tiksi | DONE
13 of 620 Requesting data for samalaeulu | Not found
14 of 620 Requesting data for butaritari | DONE
15 of 620 Requesting data for norman wells | DONE
16 of 620 Requesting data for klaksvik | DONE
17 of 620 Requesting data for souillac | DONE
18 of 620 Requesting data for illoqqortoormiut | Not found
19 of 620 Requesting data for lebu | DONE
20 of 620 Requesting data for thunder bay | DONE
21 of 620 Requesting data for kaitangata | DONE
22 of 620 Requ[...]<jupyter_text>Convert Raw Data to DataFrame* Export the city data into a .csv.* Display the DataFrame<jupyter_code>print(f'{len(cities_df)} Cities with Data') 
try:
    cities_df.set_index('City',inplace =True)
except KeyError:
    print('Index already set')
cities_df.to_csv('../output_data/cities.csv')
cities_df.head()

cities_df.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>cities_df[cities_df['Humidity']>100]
#  Get the indices of cities that have humidity over 100%.
cities_df[cities_df['Humidity']>100].index
# 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>cities_df.plot(kind='scatter',x='Lat',y='Max Temp',edgecolors='black')
plt.title('City Latitude vs Max Temp')
plt.xlabel('Latitude')
plt.ylabel('Max temperature (f)')
plt.grid()
plt.savefig('../output_data/lat_VS_maxTemp.jpg')<jupyter_output><empty_output><jupyter_text>AnalysisIn this plot you can see the expected behavior, the closer you are to the Equator the higher the temperature is.But you also can observe that is not symmetrical at 60 and -60 have different temperatures; and the maximum temperature is around 20+. with this you can infer that the planet is tilted with an angle close to 20+ Degrees.  Latitude vs. Humidity Plot<jupyter_code>cities_df.plot(kind='scatter',x='Lat',y='Humidity',edgecolors='black')
plt.title('City Latitude vs Humidity')
plt.xlabel('Latitude')
plt.ylabel('Humidity')
plt.grid()
plt.savefig('../output_data/lat_VS_Humidity.jpg')
plt.show()<jupyter_output><empty_output><jupyter_text>AnalysisIn this plot you can observed that they are much more variation on the positive latitudes than in the negative ones.you can also see a gap for low Humidity between -20 and 0; when you look a map in these coordinates you can observe that they correspond to countries like Brazil, Kongo Indonesia among others.  Latitude vs. Cloudiness Plot<jupyter_code>cities_df.plot(kind='scatter',x='Lat',y='Cloudiness',edgecolors='black')
plt.title('City Latitude vs Cloudiness')
plt.xlabel('Latitude')
plt.ylabel('Cloudiness')
plt.grid()
plt.savefig('../output_data/lat_VS_cloudiness.jpg')
plt.show()<jupyter_output><empty_output><jupyter_text>Analysis This plot is interesting because the data all over the place. you can some trends in 20 and 40 cloudiness. but would attribute this to the low density of the measurements more than a relationship among Latitude and cloudiness.  Latitude vs. Wind Speed Plot<jupyter_code>cities_df.plot(kind='scatter',x='Lat',y='Wind Speed',edgecolors='black')
plt.title('City Latitude vs Wind Speed')
plt.xlabel('Latitude')
plt.ylabel('Wind Speed')
plt.grid()
plt.savefig('../output_data/lat_VS_windSpeed.jpg')
plt.show()<jupyter_output><empty_output><jupyter_text>AnalysisIn this plot you can observe that in general is more common to have higher wind speeds the farther away from the Equator you are.  Linear Regression<jupyter_code>northern_cities = cities_df[cities_df['Lat']>0]
southern_cities = cities_df[cities_df['Lat']<0]<jupyter_output><empty_output><jupyter_text>Northern Hemisphere - Max Temp vs. Latitude Linear Regression<jupyter_code>northern_cities.plot(kind='scatter',x='Lat',y='Max Temp')
plt.title('City Latitude vs Max Temp')
plt.xlabel('Latitude')
plt.ylabel('Max temperature (f)')
plt.grid()
theta = linregress(northern_cities['Lat'],northern_cities['Max Temp'])
print(f'The r-value is : {theta.rvalue}')
line = theta.slope*northern_cities['Lat']+theta.intercept
plt.plot(northern_cities['Lat'],line,c ='r')
line_eq = f'y = {round(theta.slope,2)}x + {round(theta.intercept,2)}'
plt.annotate(line_eq,(0,20),c='r')
plt.savefig('../output_data/northLat_VS_maxTemp.jpg')
plt.show()<jupyter_output>The r-value is : -0.8726817686729642<jupyter_text>Southern Hemisphere - Max Temp vs. Latitude Linear Regression<jupyter_code>southern_cities.plot(kind='scatter',x='Lat',y='Max Temp')
plt.title('City Latitude vs Max Temp')
plt.xlabel('Latitude')
plt.ylabel('Max temperature (f)')
plt.grid()
theta = linregress(southern_cities['Lat'],southern_cities['Max Temp'])
print(f'The r-value is : {theta.rvalue}')
line = theta.slope*southern_cities['Lat']+theta.intercept
plt.plot(southern_cities['Lat'],line,c ='r')
line_eq = f'y = {round(theta.slope,2)}x + {round(theta.intercept,2)}'
plt.annotate(line_eq,(-50,40),c='r')
plt.savefig('../output_data/southLat_VS_maxTemp.jpg')
plt.show()<jupyter_output>The r-value is : 0.7371928321464308<jupyter_text>Analysiswith the trend lines across the last two plots you can observed that the closer to the equator the higher the temperature; and you can also observe that the trend line is moved upwards in the southern hemisphere.Also with the r-value you can see a good correlation for the data and trend line.   Northern Hemisphere - Humidity (%) vs. Latitude Linear Regression<jupyter_code>northern_cities.plot(kind='scatter',x='Lat',y='Humidity')
plt.title('City Latitude vs Humidity')
plt.xlabel('Latitude')
plt.ylabel('Humidity')
plt.grid()
theta = linregress(northern_cities['Lat'],northern_cities['Humidity'])
print(f'The r-value is : {theta.rvalue}')
line = theta.slope*northern_cities['Lat']+theta.intercept
plt.plot(northern_cities['Lat'],line,c ='r')
line_eq = f'y = {round(theta.slope,2)}x + {round(theta.intercept,2)}'
plt.annotate(line_eq,(50,10),c='r')
plt.savefig('../output_data/northLat_VS_humidity.jpg')
plt.show()<jupyter_output>The r-value is : 0.16864016258211212<jupyter_text>Southern Hemisphere - Humidity (%) vs. Latitude Linear Regression<jupyter_code>southern_cities.plot(kind='scatter',x='Lat',y='Humidity')
plt.title('City Latitude vs Humidity')
plt.xlabel('Latitude')
plt.ylabel('Humidity')
plt.grid()
theta = linregress(southern_cities['Lat'],southern_cities['Humidity'])
print(f'The r-value is : {theta.rvalue}')
line = theta.slope*southern_cities['Lat']+theta.intercept
plt.plot(southern_cities['Lat'],line,c ='r')
line_eq = f'y = {round(theta.slope,2)}x + {round(theta.intercept,2)}'
plt.annotate(line_eq,(-50,30),c='r')
plt.savefig('../output_data/southLat_VS_humidity.jpg')
plt.show()<jupyter_output>The r-value is : 0.046917897060224006<jupyter_text>AnalysisIn general, we can see that the latitude has poor correlation with the humidity. but we can observe that there is trend for the cities to be in places with high humidity; most of the data is has values above 20% humidity with the northern hemisphere having more cities in places with lower humidity.   Northern Hemisphere - Cloudiness (%) vs. Latitude Linear Regression<jupyter_code>northern_cities.plot(kind='scatter',x='Lat',y='Cloudiness')
plt.title('City Latitude vs Cloudiness')
plt.xlabel('Latitude')
plt.ylabel('Cloudiness')
plt.grid()
theta = linregress(northern_cities['Lat'],northern_cities['Cloudiness'])
print(f'The r-value is : {theta.rvalue}')
line = theta.slope*northern_cities['Lat']+theta.intercept
plt.plot(northern_cities['Lat'],line,c ='r')
line_eq = f'y = {round(theta.slope,2)}x + {round(theta.intercept,2)}'
plt.annotate(line_eq,(0,10),c='r')
plt.savefig('../output_data/northLat_VS_cloudiness.jpg')
plt.show()<jupyter_output>The r-value is : 0.12047639204206104<jupyter_text>Southern Hemisphere - Cloudiness (%) vs. Latitude Linear Regression<jupyter_code>southern_cities.plot(kind='scatter',x='Lat',y='Cloudiness')
plt.title('City Latitude vs Cloudiness')
plt.xlabel('Latitude')
plt.ylabel('Cloudiness')
plt.grid()
theta = linregress(southern_cities['Lat'],southern_cities['Cloudiness'])
print(f'The r-value is : {theta.rvalue}')
line = theta.slope*southern_cities['Lat']+theta.intercept
plt.plot(southern_cities['Lat'],line,c ='r')
line_eq = f'y = {round(theta.slope,2)}x + {round(theta.intercept,2)}'
plt.annotate(line_eq,(-50,20),c='r')
plt.savefig('../output_data/southLat_VS_cludiness.jpg')
plt.show()<jupyter_output>The r-value is : 0.1421271588953497<jupyter_text>AnalysisThere is a low correlation between Cloudiness and latitude. but can observe more cloudiness in general in the northern hemisphere.   Northern Hemisphere - Wind Speed (mph) vs. Latitude Linear Regression<jupyter_code>northern_cities.plot(kind='scatter',x='Lat',y='Wind Speed')
plt.title('City Latitude vs Wind Speed')
plt.xlabel('Latitude')
plt.ylabel('Wind Speed')
plt.grid()
theta = linregress(northern_cities['Lat'],northern_cities['Wind Speed'])
print(f'The r-value is : {theta.rvalue}')
line = theta.slope*northern_cities['Lat']+theta.intercept
plt.plot(northern_cities['Lat'],line,c ='r')
line_eq = f'y = {round(theta.slope,2)}x + {round(theta.intercept,2)}'
plt.annotate(line_eq,(0,12),c='r')
plt.savefig('../output_data/northLat_VS_windSpeed.jpg')
plt.show()<jupyter_output>The r-value is : 0.1029268870400224<jupyter_text>Southern Hemisphere - Wind Speed (mph) vs. Latitude Linear Regression<jupyter_code>southern_cities.plot(kind='scatter',x='Lat',y='Wind Speed')
plt.title('City Latitude vs Wind Speed')
plt.xlabel('Latitude')
plt.ylabel('Wind Speed')
plt.grid()
theta = linregress(southern_cities['Lat'],southern_cities['Wind Speed'])
print(f'The r-value is : {theta.rvalue}')
line = theta.slope*southern_cities['Lat']+theta.intercept
plt.plot(southern_cities['Lat'],line,c ='r')
line_eq = f'y = {round(theta.slope,2)}x + {round(theta.intercept,2)}'
plt.annotate(line_eq,(-50,9),c='r')
plt.savefig('../output_data/southLat_VS_windSpeed.jpg')
plt.show()<jupyter_output>The r-value is : -0.08048107352558777
{'fraction_non_alphanumeric': 0.1340993328391401, 'fraction_numerical': 0.025945144551519646, 'mean_word_length': 6.2260310658810925, 'pattern_counts': {'":': 0, '<': 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': '385160', 'license': 'MIT', 'n_tokens_mistral': 5014, 'n_tokens_neox': 4568, 'n_words': 1191, 'path': 'WeatherPy/WeatherPy.ipynb', 'repo_name': 'Momoyactly/python-api-challenge', 'size': '13490'}