from pandas import DataFrame
# response to
# https://www.sololearn.com/Discuss/1619569/loading-data-from-csv-file-into-new-variables
#from pandas import read_csv
from numpy import npv
# simulation of .csv file
col = ['project name', 'a value', 'starting capital', \
'year1','year2','year3','year4','year5','year6']
data = [['a', 0.10, -10000, 900, 2000, 2000, 3000, 4000, 4500 ],
['b', 0.10, -20000, 2000, 2500, 3000, 4000, 4000, 5000 ],
['c', 0.10, -35000, 3400, 3500, 4000, 5000, 6000, 6500 ]]
def maxnpv():
if (npvA > npvB) and (npvA > npvC):
res = "A"
elif (npvB > npvA) and (npvB > npvC):
res = "B"
else:
res = "C"
print("Most profitable is " +res +".")
fund = DataFrame(data, columns = col)
# fund = read_csv("inwestycje.csv", delimiter=',')
# version for n projects
np_list = []
for index, row in fund.iterrows():
row = row.tolist()
np_list.append( npv(row[1], row[2:]) )
# variables for maxnpv()
prjN = row[0].upper()
exec( "npv"+prjN+" = np_list[index]" ) #create npvA, npvB, npvC
# output
print("NPV for project '{}': PLN {:,.2f}".format(prjN, np_list[index] ))
maxnpv()