I converted my csv file to text file and I want to add the numbers inside the text file. When I run my code get an error. Assuming the error code I want to write logic that woul
Modified your code as mentioned below:
with open(r'annual_budget.txt', 'r') as f:
reader = csv.reader(f)
headers = reader.next() # this will yield first row i.e columns if python 3: Use next(reader) instead of reader.next()
for line in reader:
rowdata = map(float, line)
data.extend(rowdata)
print(sum(data)/len(data))