Sep-07-2024, 09:43 AM
Hi, im trying to understand what is causing me my issue.It used to work!
Last time i ran this code was about a year ago
Is this python , pandas or streamlit ?
I have this code to map zips ( first 3 digits of the zips )
Last time i ran this code was about a year ago
Is this python , pandas or streamlit ?
I have this code to map zips ( first 3 digits of the zips )
def area_zips(zipcode): zips = {"010": "Springfield", "011": "Springfield", "012": "Springfield", "013": "Springfield", "014": "Boston"} return zips[zipcode[:3]] df["PuMarket"] = df["PuZip"].map(area_zips)This code to map states:
def regions(region): states = {"ME": "Northeast", "NH": "Northeast"} return states[region] df["PuRegion"] = df["PuState"].map(regions)i get errors. Error sample for zip codes, but same errors if i remove zips and leave region code.
Error: KeyError: ''
Traceback:
File "/development/koala/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/exec_code.py", line 88, in exec_func_with_error_handling
result = func()
^^^^^^
File "/development/koala/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 590, in code_to_exec
exec(code, module.__dict__)
File "/development/koala/1_Home.py", line 169, in <module>
df = load_data()
^^^^^^^^^^^
File "/development/koala/lib/python3.12/site-packages/streamlit/runtime/caching/cache_utils.py", line 210, in __call__
return self._get_or_create_cached_value(args, kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/development/koala/lib/python3.12/site-packages/streamlit/runtime/caching/cache_utils.py", line 235, in _get_or_create_cached_value
return self._handle_cache_miss(cache, value_key, func_args, func_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/development/koala/lib/python3.12/site-packages/streamlit/runtime/caching/cache_utils.py", line 288, in _handle_cache_miss
computed_value = self._info.func(*func_args, **func_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/development/koala/1_Home.py", line 102, in load_data
df["PuMarket"] = df["PuZip"].map(area_zips)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/development/koala/lib/python3.12/site-packages/pandas/core/series.py", line 4700, in map
new_values = self._map_values(arg, na_action=na_action)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/development/koala/lib/python3.12/site-packages/pandas/core/base.py", line 921, in _map_values
return algorithms.map_array(arr, mapper, na_action=na_action, convert=convert)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/development/koala/lib/python3.12/site-packages/pandas/core/algorithms.py", line 1743, in map_array
return lib.map_infer(values, mapper, convert=convert)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "lib.pyx", line 2972, in pandas._libs.lib.map_infer
File "/development/koala/1_Home.py", line 100, in area_zips
return zips[zipcode[:3]]
~~~~^^^^^^^^^^^^^
Thank You.