<jupyter_start><jupyter_text>Weather API data<jupyter_code>import pandas as pd
import requests
import json
import re
from datetime import datetime, date, timedelta
from IPython.display import JSON
import numpy as np
from my_access import visual_crossing, visual_crossing2<jupyter_output><empty_output><jupyter_text>Get Coordinates for AirportsLatitude and longitude data from the [airport codes dataset](https://datahub.io/core/airport-codesresource-airport-codes)<jupyter_code># get airport codes from flights table
ori = pd.read_csv('flights_sample_random_cleaned.csv').origin.unique()
dest = pd.read_csv('flights_sample_random_cleaned.csv').dest.unique()
airport_codes = np.union1d(ori, dest)
apts = pd.read_csv('airport-codes_csv.csv')
apts = apts[apts.iso_country == "US"]
apts = apts[['iata_code', 'coordinates']].set_index('iata_code')
def swap(c):
    l = c.split(",")
    return f"{l[1].strip()}, {l[0].strip()}"
    
apts['coordinates'] = apts['coordinates'].apply(swap)
latlong = []
for code in airport_codes:
    try:
        latlong.append(apts.loc[code].coordinates)
    except KeyError:
        latlong.append(np.nan)
apt_coords = pd.DataFrame(latlong, index=airport_codes, columns=['lat_long'])
# apt_coords.to_csv('airport_coordinates.csv')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13131313131313133, 'fraction_numerical': 0.003108003108003108, 'mean_word_length': 6.488372093023256, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 1, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '563018', 'license': 'MIT', 'n_tokens_mistral': 452, 'n_tokens_neox': 446, 'n_words': 87, 'path': 'Oliver_workspace/weather_data.ipynb', 'repo_name': 'robynmundle/predicting_flight_delays', 'size': '1287'}