Created
July 25, 2017 20:47
-
-
Save jbvimort/f0267dbe9fd47853ce0ffa5dd81829ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import csv | |
import re | |
dataDir = "/home/jean-baptiste/Documents/4Neighborhood/CSVfeatureMaps/" | |
with open('trainingData.csv', 'w') as csvWritefile: | |
fieldnames = ['ID', 'Energy', 'Entropy', 'Correlation', 'InverseDifferenceMoment','Inertia', 'ClusterShade', | |
'ClusterProminence', 'HarralickCorrelation','ShortRunEmphasis', 'LongRunEmpasis','GreyLevelNonUniformity', | |
'RunLengthNonUniformity','LowGreyLevelRunEmphasis', 'HighGreyLevelRunEmphasis', | |
'ShortRunLowGreyLevelEmphasis', 'ShortRunHighGreyLevelEmphasis','LongRunLowGreyLevelEmphasis', 'LongRunHighGreyLevelEmphasis'] | |
writer = csv.DictWriter(csvWritefile, fieldnames=fieldnames) | |
writer.writeheader() | |
for fileName in os.listdir(dataDir): | |
with open(dataDir + fileName, 'rb') as csvfile: | |
spamreader = csv.DictReader(csvfile, delimiter=',', quotechar='|') | |
for row in spamreader: | |
if(row['X'] == '15' and row['Y'] == '15' and row['Z'] == '15'): | |
row['ID'] = re.search("_(.+?)_FeatureMap.csv", fileName).group(1) | |
row.pop('', None) | |
row.pop('X', None) | |
row.pop('Y', None) | |
row.pop('Z', None) | |
writer.writerow(row) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment