Extracting values from lists and converting to ints

Posted 13 October 2011 - 08:08 PM

Hello,
so this is homework project in which we have to open a file from excel and take the values the numbers in each line and do an operation to find a final value, however the values are all in one cell. I am struggling with just extracting each number after I append them to their respective lists. I was hoping for some guidance, thanks (code is below).
,2003,2004,2005,2006,2007,2008,2009
Income statement,,,,,,,
Total Revenue,4075.52,5294.25,6369.3,7786.94,9411.5,9774.6,10707.4
Operating Income,420.85,606.49,780.52,893.95,1053.94,562,1419.4
Net Income,265.36,388.88,494.37,564.26,672.64,390.8,945.6
Balance Sheet,,,,,,,
Total Assets,2778.53,3386.54,3513.69,4428.94,5343.88,5576.8,6385.9
Total Equity,2071.11,2470.21,2090.26,2228.51,2284.12,3045.7,3674.7
Total Liabilities,707.42,916.33,1423.43,2200.43,3059.76,2531.1,2711.2
Cash Flow,,,,,,,
Operating,616.12,862.92,922.91,1131.63,1331.22,1389,1704.9
Investing,-616.42,-753.89,-220.62,-841.04,-1201.95,-421.1,-789.5
Financing,30.76,-66.55,-673.83,-155.33,-171.89,-642.2,-346
Net Cash Change,33.73,45.59,28.76,138.8,-31.34,330,564.2

Replies To: Extracting values from lists and converting to ints

Re: Extracting values from lists and converting to ints

Posted 13 October 2011 - 08:41 PM

Lets assume we want to grab out the first value in the "Operating" line under Cash Flow. Lets say this line is loaded into listfile as index 10. We can then get access to this value by using two indexes. One to access the line, the second to access the value in that line...

print "First operating value: " + listfile[10][1]

So we are saying "Go to the 11 line, grab the second value (since "Operating" is the first value). Array indexes start from 0.

That is how you can pull out each value. To sum them up, think about looping through a given list.

Will split the line into strings, which will give an error if you try to sum them up. So you either need to calculate them on the fly, as floats converted from strings, or calculate them all all store them back in the array.