Jun-20-2024, 07:59 PM
It looks like the issue might be due to the way you're trying to access the values in the year3paytest column. Instead of directly using [0][0], try iterating through the rows or using apply again to split the values. # Assuming semiannualpayments returns a tuple like (1500, 1505) cleandata["year3paytest"] = cleandata.apply(lambda x: semiannualpayments(x["owneroccupancycode"], x["year3total"], x["county"]), axis=1) # Split the tuples into two separate columns cleandata["year3pay1"] = cleandata["year3paytest"].apply(lambda x: x[0]) cleandata["year3pay2"] = cleandata["year3paytest"].apply(lambda x: x[1]) This should help you split the tuple values into two separate columns without running into the KeyError. Give it a try and see if it resolves the issue!