Apr-07-2023, 01:54 AM
I have the following code snippet from my script
This works without issue in a smaller snippet of code that I have for my initial testing. The only thing that changed was the dataframe name and the amount of rows in that dataframe.
What am I missing here?
cleandata["year3paytest"] = cleandata.apply(lambda x: semiannualpayments(x["owneroccupancycode"], x["year3total"], x["county"]), axis=1) cleandata["year3pay1"] = cleandata["year3paytest"][0][0] cleandata["year3pay2"] = cleandata["year3paytest"][0][1] #TODO:enter semiannualpayments in clendadata dfIt throws the following error:
Error:File "pandas\_libs\index.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\index.pyx", line 165, in pandas._libs.index.IndexEngine.get_loc
File "pandas\_libs\hashtable_class_helper.pxi", line 2263, in pandas._libs.hashtable.Int64HashTable.get_item
File "pandas\_libs\hashtable_class_helper.pxi", line 2273, in pandas._libs.hashtable.Int64HashTable.get_item
KeyError: 0
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\GitHub\PropertyTax\tanyardsprings.py", line 219, in <module>
cleandata["year3pay1"] = cleandata["year3paytest"][0][0]
~~~~~~~~~~~~~~~~~~~~~~~~~^^^
File "C:\GitHub\PropertyTax\venv\Lib\site-packages\pandas\core\series.py", line 981, in __getitem__
return self._get_value(key)
^^^^^^^^^^^^^^^^^^^^
File "C:\GitHub\PropertyTax\venv\Lib\site-packages\pandas\core\series.py", line 1089, in _get_value
loc = self.index.get_loc(label)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\GitHub\PropertyTax\venv\Lib\site-packages\pandas\core\indexes\base.py", line 3804, in get_loc
raise KeyError(key) from err
KeyError: 0
Process finished with exit code 1
What I am trying to do is to split the values into two different columns in the data frame. For example the value of year3paytest is the (1500,1505). I want the first value to now be year3pay1 and then the second to be year3pay2. This works without issue in a smaller snippet of code that I have for my initial testing. The only thing that changed was the dataframe name and the amount of rows in that dataframe.
What am I missing here?