From d1ee9e276e537a94f766fd2a270744875ce96d62 Mon Sep 17 00:00:00 2001 From: Olivia Date: Thu, 9 Dec 2021 12:20:52 +0000 Subject: [PATCH 1/2] Change the read_csv functions --- analysis/workflow1.py | 52 +++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/analysis/workflow1.py b/analysis/workflow1.py index eff5dae..53ca925 100644 --- a/analysis/workflow1.py +++ b/analysis/workflow1.py @@ -1,37 +1,41 @@ from math import * - +import pandas as pd # read sample files -with open('data1.csv') as file1: - lines1 = file1.readlines() - data1 = [] - for line in lines1: - row = [] - for n in line.split(','): - row.append(float(n.strip())) - data1.append(row) +# with open('data1.csv') as file1: +# lines1 = file1.readlines() +# data1 = [] +# for line in lines1: +# row = [] +# for n in line.split(','): +# row.append(float(n.strip())) +# data1.append(row) + +data1=pd.read_csv('data1',header=None,sep=' ') +data2=pd.read_csv('data2',header=None,sep=' ') +weight=pd.read_csv('weights',header=None,sep=' ') -with open('data2.csv') as file2: - lines2 = file2.readlines() - data2 = [] - for line in lines2: - row = [] - for n in line.split(','): - row.append(float(n.strip())) - data2.append(row) +# with open('data2.csv') as file2: +# lines2 = file2.readlines() +# data2 = [] +# for line in lines2: +# row = [] +# for n in line.split(','): +# row.append(float(n.strip())) +# data2.append(row) -with open('weights.csv') as filew: - linew = filew.read() - w = [] - for n in linew.split(','): - w.append(float(n.strip())) +# with open('weights.csv') as filew: +# linew = filew.read() +# w = [] +# for n in linew.split(','): +# w.append(float(n.strip())) results = [] for i in range(len(data1)): s = 0 - for j in range(len(w)): + for j in range(len(weight)): d = data1[i][j] - data2[i][j] - s += w[j] * abs(d) + s += weight[j] * abs(d) results.append(s) critical = 0 From 20553fbbf866dc2cd22a65c78162ab8f71297095 Mon Sep 17 00:00:00 2001 From: Olivia Date: Thu, 9 Dec 2021 12:21:50 +0000 Subject: [PATCH 2/2] Simplify the printing messages. --- analysis/workflow1.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/analysis/workflow1.py b/analysis/workflow1.py index 53ca925..6ed9728 100644 --- a/analysis/workflow1.py +++ b/analysis/workflow1.py @@ -42,7 +42,5 @@ for i in range(len(results)): # for all i if results[i] > 5: critical = critical + 1 # increase by 1 -if critical == 1: - print("criticality: 1 result above 5") -else: - print("criticality:", critical, "results above 5") + +print("criticality:", critical, "results above 5")