samedi 27 février 2016

Pull column B (amount) based on the column C (category) from excel and compute in python

import xlrd
import numpy

fileWorkspace = 'C://Users/doj/Desktop/'

wb1 = xlrd.open_workbook(fileWorkspace + 'assignment.xls')
sh1 = wb1.sheet_by_index(0)

time,amount,category = [],[],[]
for a in range(2,sh1.nrows):
    time.append(int(sh1.cell(a,0).value))
    amount.append(float(sh1.cell(a,1).value))
    category.append(str(sh1.cell(a,2).value))
#print(time)
#print(amount)
print(category)
print('\n')

p_p2 = str(sh1.cell(0,1))
p_p1 = p_p2.replace("text:'","")
pp = p_p1.replace("'","")
print(pp)
c_p2 = str(sh1.cell(1,1))
c_p1 = c_p2.replace("text:'","")
cp = c_p1.replace("'","")
print(cp)

netflow = 0
outflow = 0
inflow = 0
flow = 0

a = []
category = ["'Sales'", "'Salvage'", "'Subsidy'", "'Redeemable'", "'Utility'", "'Labor'", 
            "Testing", "Marketing", "Materials", "Logistics"]

if pp == "Years" and cp == "Years":

    IRR = numpy.irr(amount) * 100
    print ("IRR:", round(IRR, 2), '%', '\n')

    for i in category:
        if category == [5]:
            flow = amount[i] / numpy.power((1 + (IRR/100)), time[i])
            if flow>0:                      
                inflow = inflow + flow      
            if flow<0:                      
                outflow = outflow + flow  

            a.append(flow)
            print(a)
            print ('Present Value (P) is:', round(flow,0), '\n')

I need to illustrate the breakdown of major project revenues and expenses by category as a percentage of that project’s future value in 2025. The illustration must also clearly indicate the total future value of the project in year 2025 as well as the IRR.

I am totally confused what I am doing wrong with my code. I understand what to do, but I just can't code it.

Below is the image of the Excel File I have:

Excel File

Aucun commentaire:

Enregistrer un commentaire