CoolFace
Apppublic

williambr/SteamlitMapPractice2

sourceHugging Facemitupdated 4y agoView on Hugging Face
1likes
Map-PyCode-City-State-Zip-Lat-Long-SampleCode.txt45 linesDownload Raw Back to root
1import definitions2import pandas as pdb3from typing import NamedTuple, Dict4 5_ROOT_DIR = definitions.get_project_root()6 7 8class ZipCodeEntry(NamedTuple):9    zip: str10    city: str11    state: str12    lat: str13    long: str14    time_zone: str15    dst_flags: bool16 17 18def _load_zip_codes() -> Dict[str, ZipCodeEntry]:19    df = pdb.read_csv(f'{_ROOT_DIR}/utils/us-zip-code-latitude-and-longitude.txt', dtype=str,20                      sep=';')21    zip_code_list = {}22    # Zip;City;State;Latitude;Longitude;Timezone;Daylight savings time flag;geopoint23    for _, row in df.iterrows():24        zip_code = row.get('Zip')25        if zip_code:26            zip_code_entry = ZipCodeEntry(27                zip=zip_code,28                city=row.get('City'),29                state=row.get('State'),30                lat=row.get('Latitude'),31                long=row.get('Longitude'),32                time_zone=row.get('Timezone'),33                dst_flags=row.get('Daylight savings time flag')34            )35            zip_code_list[zip_code] = zip_code_entry36 37    return zip_code_list38 39 40ZIP_CODE_LIST = _load_zip_codes()41 42 43if __name__ == '__main__':44    print(ZIP_CODE_LIST)45    print(ZIP_CODE_LIST.get('62833'))