Mar-25-2023, 03:23 AM
I am pulling/wanting to pull in data from a pandas data frame to a straight variable so I can do pull it into a function so I do not duplicate code. When I do it it is not hitting the conditions as expected.
7651/7651b.csv
other files
limits.py
7651/7651b.csv
key,address,accountnumber,opendataupdate,housetype,landuse,exemptclass,assessmentyear,currentyeartotalassessment,owneroccupancycode,homesteadcreditqualificationcode,homesteadqualificationdate,yearbuilt,datepurchased,zoning,box2,box4,box5,box6,box8,box7,box9a,box9,box10,totalchange 79790234333,7651 TIMBERCROSS LN,79790234333,20230303,TH,Residential (R),Blank,2023,310500,Yes,Approved,2015.01.14,2014,2014.07.31,,310500,290000,120000,231500,310500,351500,20500.0,331000.0,351500,615007651.py
# !/usr/bin/env python author = "Michael Brown" import pandas as pd from limits import statelimit, annearundelcountylimit from rates import statetaxrate, annearundeltaxrate, annearundelsolidwaste, annearundelstormwater from warnings import simplefilter simplefilter(action="ignore", category=pd.errors.PerformanceWarning) tanyardTH = pd.read_csv('test/7651b.csv') # year 1 calculation tanyardTH['year1difference'] = tanyardTH['box8'] - tanyardTH['box4'] tanyardTH['year1countylimit'] = tanyardTH['box4'] + (tanyardTH['box4'] * annearundelcountylimit) tanyardTH['year1statelimit'] = tanyardTH['box4'] + (tanyardTH['box4'] * statelimit) tanyardTH['year1countydifference'] = tanyardTH['box8'] - tanyardTH['year1countylimit'] tanyardTH['year1statedifference'] = tanyardTH['box8'] - tanyardTH['year1statelimit'] # year1 county credit calculation tanyardTH.loc[tanyardTH['year1countydifference'] < 0, 'year1countycredit'] = 0 tanyardTH.loc[tanyardTH['year1countydifference'] > 0, 'year1countycredit'] = (tanyardTH[ 'year1countydifference'] * annearundeltaxrate) / 100 # year 1 state credit calculation tanyardTH.loc[tanyardTH['year1statedifference'] < 0, 'year1statecredit'] = 0 tanyardTH.loc[tanyardTH['year1statedifference'] > 0, 'year1statecredit'] = (tanyardTH[ 'year1statedifference'] * statetaxrate) / 100 # year 1 straight real estate tax payment without exempt class tanyardTH['year1countyrealestate'] = (tanyardTH['box8'] * annearundeltaxrate) / 100 tanyardTH['year1staterealestate'] = (tanyardTH['box8'] * statetaxrate) / 100 tanyardTH['year1total'] = tanyardTH['year1countyrealestate'] + tanyardTH['year1staterealestate'] - tanyardTH[ 'year1countycredit'] - tanyardTH['year1statecredit'] + annearundelsolidwaste + annearundelstormwater # year 2 calculation tanyardTH['year2countylimit'] = tanyardTH['year1countylimit'] + (tanyardTH['year1countylimit'] * annearundelcountylimit) tanyardTH['year2statelmit'] = tanyardTH['box2'] + (tanyardTH['box2'] * statelimit) tanyardTH['year2countydifference'] = tanyardTH['box9'] - tanyardTH['year2countylimit'] tanyardTH['year2statedifference'] = tanyardTH['box8'] - tanyardTH['year2statelmit'] # year 2 county credit calculation tanyardTH.loc[tanyardTH['year2countydifference'] < 0, 'year2countycredit'] = 0 tanyardTH.loc[tanyardTH['year2countydifference'] > 0, 'year2countycredit'] = (tanyardTH[ 'year2countydifference'] * annearundeltaxrate) / 100 # year 2 state credit calculation tanyardTH.loc[tanyardTH['year2statedifference'] < 0, 'year2statecredit'] = 0 tanyardTH.loc[tanyardTH['year2statedifference'] > 0, 'year2statecredit'] = (tanyardTH[ 'year2statedifference'] * statetaxrate) / 100 # year 2 straight real estate tax payment without exempt class tanyardTH['year2countyrealestate'] = (tanyardTH['box9'] * annearundeltaxrate) / 100 tanyardTH['year2staterealestate'] = (tanyardTH['box9'] * statetaxrate) / 100 tanyardTH['year2total'] = tanyardTH['year2countyrealestate'] + tanyardTH['year2staterealestate'] - tanyardTH[ 'year2countycredit'] - tanyardTH['year2statecredit'] + annearundelsolidwaste + annearundelstormwater # year 3 calculation tanyardTH['year3countylimit'] = tanyardTH['year2countylimit'] + (tanyardTH['year2countylimit'] * annearundelcountylimit) tanyardTH['year3statelimit'] = tanyardTH['box9'] + (tanyardTH['box9'] * statelimit) tanyardTH['year3countydifference'] = tanyardTH['box10'] - tanyardTH['year3countylimit'] tanyardTH['year3statedifference'] = tanyardTH['box9'] - tanyardTH['year3statelimit'] # year 3 county credit calculation tanyardTH.loc[tanyardTH['year3countydifference'] < 0, 'year3countycredit'] = 0 tanyardTH.loc[tanyardTH['year3countydifference'] > 0, 'year3countycredit'] = (tanyardTH[ 'year3countydifference'] * annearundeltaxrate) / 100 # year 3 state credit calculation tanyardTH.loc[tanyardTH['year3statedifference'] < 0, 'year3statecredit'] = 0 tanyardTH.loc[tanyardTH['year3statedifference'] > 0, 'year3statecredit'] = (tanyardTH['year3statedifference'] * statetaxrate) / 100 # year3 straight real estate tax payment without exempt class tanyardTH['year3countyrealestate'] = (tanyardTH['box10'] * annearundeltaxrate) / 100 tanyardTH['year3staterealestate'] = (tanyardTH['box10'] * statetaxrate) / 100 tanyardTH.loc[(tanyardTH['owneroccupancycode'] == 'Yes') & (tanyardTH['homesteadcreditqualificationcode'] == 'Approved'), 'year3total']\ = (tanyardTH['year3countyrealestate'] + tanyardTH['year3staterealestate'] - tanyardTH['year3countycredit'] - tanyardTH['year3statecredit'] + annearundelsolidwaste + annearundelstormwater) tanyardTH.loc[(tanyardTH['owneroccupancycode'] != 'Yes') | (tanyardTH['homesteadcreditqualificationcode'] != 'Approved'), 'year3total'] = (tanyardTH['year3countyrealestate'] + tanyardTH['year3staterealestate'] + annearundelsolidwaste + annearundelstormwater) from functions import test tanyardTH[["exemptclass"]].to_numpy() test = test(tanyardTH['owneroccupancycode'],tanyardTH['homesteadcreditqualificationcode'], tanyardTH['exemptclass'], tanyardTH['year3countyrealestate'], tanyardTH['year3staterealestate'], tanyardTH['year3countycredit'], tanyardTH['year3statecredit']) #functions can only have 2 arguments? # debugging print(tanyardTH) tanyardTH.to_csv('7651.csv') print(tanyardTH.info())functions.py
def owneroccupancycondition(x): if x == "H": return "Yes" elif x == "N": return " No " else: return "0" def yearcondition(x): if x == "O": return "1899" else: return x def homesteadqualiticationcondition(x): if x == "A": return "Approved" if x == "X": return "Denied" else: return "No Application" def test(owneroccupied, homesteadcode, exemptclass, year3countyrealestate, year3staterealestate, year3countycredit, year3statecredit): from rates import statetaxrate, annearundeltaxrate, annearundelsolidwaste, annearundelstormwater if ("exemptclass" != "Blank"): taxbill = annearundelsolidwaste + annearundelstormwater return taxbill if ("exemptclass" == "Blank"): if ("owneroccupied" == "Yes"): taxbill = year3countyrealestate + year3staterealestate - year3countycredit - year3statecredit + annearundelsolidwaste + annearundelstormwater return taxbill else: taxbill = year3countyrealestate + year3staterealestate + annearundelsolidwaste + annearundelstormwater return taxbill else: taxbill = 0 return taxbillThe exemptclass is coming back to Blank but it is showing it up as an array versus a straight value of "Blank". What am I missing
other files
limits.py
statelimit = 0.10 annearundelcountylimit = 0.02rates.py
#state rates statetaxrate = 0.1120 #anne arundel county rates annearundeltaxrate = .93300 annearundelsolidwaste = 341 annearundelstormwater = 35.70