-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathError_Eggplant.py
76 lines (60 loc) · 1.93 KB
/
Error_Eggplant.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
75
76
# -*- coding: utf-8 -*-
"""
Created on Sat Nov 21 21:05:15 2015
@author: Patrick C. Payne
"""
import sys
import xlrd
from pylab import *
#--------------No Need to Go beyond this point----------------------
def ImportData(filename, sheetnumb):
global content
global sheet
values = []
if filename.endswith('.xlsx') or filename.endswith('.xls'):
content = xlrd.open_workbook(filename, 'r')
sheet = content.sheet_by_index(sheetnumb)
column = sheet.ncols
row = sheet.nrows
excel = True
elif filename.endswith('.csv') or filename.endswith('.txt') or filename.endswith('.dat'):
print r'Delimeter: %r'% delimiter(filename)
content = genfromtxt(filename, delimiter=delimiter(filename))
column = len(content[0])
row = len(content)
excel = False
else:
sys.exit("Wtf, mate?")
print '# of Columns: %d'% column
print '# of Rows: %d'% row
for j in range(column):
data = []
counter = 0
for i in range(0, row):
try:
data.append(float(point(i,j, excel)))
except:
if counter == 0:
print 'Column %d title: %s'%(j,point(i,j, excel))
counter +=1
else:
break
values.append(data)
return values
def delimiter(filename):
with open(filename, 'r') as content:
header=content.readline()
if header.find(";")!=-1:
return ";"
if header.find(",")!=-1:
return ","
if header.find("\t")!=-1:
return "\t"
return "Could not detect column delimiter"
def point(i,j, excel):
if excel:
return sheet.cell(i,j).value
else:
return content[i,j]
if __name__ == '__main__':
main()