From 82d48d3936909c5f89e84dc039b60c83bec06134 Mon Sep 17 00:00:00 2001 From: Renee Hlozek Date: Wed, 4 Dec 2019 08:51:36 -0500 Subject: [PATCH] code to adjust csv files --- organize_csv.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 organize_csv.py diff --git a/organize_csv.py b/organize_csv.py new file mode 100644 index 0000000..c58f6d0 --- /dev/null +++ b/organize_csv.py @@ -0,0 +1,48 @@ +import pylab as pl +import pandas as pd +import numpy as np + +list = ['2_MikeSilogram', '3_MajorTom'] + +kyle = pd.read_csv('examples/plasticc/1_Kyle/1_Kyle.csv') +kylecols = kyle.columns.tolist() + + +matstruc = kyle.copy() +matstrucdat = np.array(matstruc) +indexlist = np.zeros(len(kylecols)) +print(kylecols) +print(matstrucdat[0,:]) + + +truth = pd.read_csv('1_Kyle/1_Kyle_truth.csv') + +for file in list: + name = file+'/'+file+'.csv' + print(name) + mat = pd.read_csv(name) + matdat = np.array(mat) + + cols = mat.columns.tolist() + index = mat.index + #print(np.shape(mat)) + print(cols) + print(matdat[0,:], 'test before') + + + for i in range(len(kylecols)): +# df[col] = df[col].replace(findL, replaceL) + for j in range(len(cols)): + if cols[j]==kylecols[i]: + indexlist[i]=j + matstrucdat[:,i] = matdat[:,j] + print(i, j, cols[j], kylecols[i]) + + matstruc.rename(columns={"A": "a", "B": "c"}) + print(matstrucdat[0,:], 'test after') + + newname = file+'/'+file+'_reordered.csv' + newnametruth = file+'/'+file+'_reordered_truth.csv' + + matstruc.to_csv(newname, index=False) + truth.to_csv(newnametruth)