-1

I have a code where I have calculated heights of random trees using data from a csv file, I have managed to output the heights of each tree, note that I have 5 heights per tree due to how the data was presented, so I need to average out those 5 values to get the height of each tree so I know I am supposed to save to format that is iterable but I cant seem to get it right. I am fairly new to Python and would love some help on this.

I have tried a for loop, so I can take the average but i'm still stuck on the error that "it is not iterable". The code below is what I have so far.

from S11151996_toolbox import *


def main():
    #Opens both data files - Students and Trees
    student_data_filename ="../Files/Student_Details.csv"
    student_details = file_read(student_data_filename)
    #print student_details

    tree_filename = "../Files/Wednesday_Tree_Data.csv"
    tree_data = file_read(tree_filename)
    #print tree_data # print tree data

    # Loop through the tree data and identify each column (NB** reading starts at 0)
    for each in tree_data:
        paces = float(each[1]) #Second column of tree file 
        angle = float(each[5])
        tree_num = int(each[3])
        name = each[4] #access the name of the student
        

        for people  in student_details:# link the 2 files together
            if name == people[3]: #if people's name from tree data matches to people's name in student data   run the loop.
                eh = float(people[1])
                pf = float(people[2])
                distance = length_pace2M(paces,pf)
                height = tree_height_calc(distance, angle, eh)
                #A = sum(height)
                #print(height)

                if tree_num ==1:
                    print(sum(height))
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153

0 Answers0