-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathavgDiffCalculator.py
More file actions
29 lines (25 loc) · 985 Bytes
/
Copy pathavgDiffCalculator.py
File metadata and controls
29 lines (25 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import csv
import os
import re
#Calculates the average difference between corresponding elements of two lists.
def average_difference(list1, list2):
if not list1 or not list2 or len(list1) != len(list2):
return None
differences = [abs(float(x) - float(y[:-2])) for x, y in zip(list1, list2)]
return sum(differences) / len(differences)
#Extracts a specific column from a text file and returns it as a list.
def column_to_list(file_path, column_index, delimiter='|'):
try:
with open("output.txt", 'r') as file:
column_list = []
for line in file:
values = line.strip().split(delimiter)
if column_index < len(values):
column_list.append(values[column_index])
return column_list
except FileNotFoundError:
print(f"Error: File not found at '{file_path}'")
return []
except Exception as e:
print(f"An error occurred: {e}")
return []