-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
74 lines (61 loc) · 2.23 KB
/
functions.py
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Import modules
import csv
import natsort
import statistics
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
#-----------Standard Mathematical Operators------------#
# Subtract list elements from other list elements
def subtract (list1, list2):
return np.subtract(list1, list2)
# Divide list elements from other list elements
def divide (list1, list2):
return [float(ai) / bi for ai, bi in zip(list1, list2)]
#----------------Statistical Calculations--------------#
# Calculate mean from list
def mean (list):
return statistics.mean(list)
# Define the range function
def getRange(list):
return max(list) - min(list) # Finds the range by subtracting the maximum by the minimum
#---------List Operations and File Functions-----------#
# Sorts list elements that are strings
def sort (list):
return natsort.natsorted(list, reverse = False)
# Converts list string elements to float
def convertToFloat (list):
list = [float(i) for i in list]
return list
# List names of files and create a list of those names
def namesList (file_list):
file_list = ' '.join(file_list).replace('.CSV','').split() # Takes out the .csv extensions
# print(file_list)
list = [int(x) for x in file_list] # Represents the names of the list as integers
list.sort() # Sorts the elements in the list
return list
# Takes the column selected and turns it into a list for a selected file
def columnList(path, column):
list = []
with open(path, "r") as csv_file:
csv_reader = csv.reader(csv_file, delimiter = ',')
for lines in csv_reader:
list.append(lines[column])
return list
def read_csv(filename):
df = pd.read_csv(filename)
return df
# Adds a new column of data to the .csv log file
def addCsvColumn (log_path, difference_list, header):
with open(log_path + 'difference_range.csv', 'wb') as f:
f.write("\n".join(difference_list))
f.close()
def fname(arg):
# Write results to a .csv file when a new file is tested
with open(log_path + 'difference_mean.csv', 'wb') as f:
f.write("\n".join(difference_mean))
f.close()
with open(log_path + 'difference_range.csv', 'wb') as f:
f.write("\n".join(difference_range))
f.close()
pass