aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/read_excel.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/python/read_excel.py b/python/read_excel.py
new file mode 100644
index 00000000..d07666f4
--- /dev/null
+++ b/python/read_excel.py
@@ -0,0 +1,31 @@
+import os
+from xlrd import open_workbook
+import csv
+
+rootdir = "/home/share/rmbs/data/finra/"
+
+
+dir_list = os.listdir(rootdir)
+dir_list = [d for d in dir_list if "zip" not in d]
+
+for d in dir_list:
+ file_list = os.listdir(os.path.join(rootdir, d))
+ for f in file_list:
+ if "xls" in f:
+ wb = open_workbook(os.path.join(rootdir, d, f))
+ with open( os.path.join(rootdir, d, f.split(".")[0] + ".csv"), "w") as fh:
+ wbcsv = csv.writer(fh, dialect = csv.excel)
+ if "PXTABLES" in f:
+ s = wb.sheets()[3]
+ else:
+ s = wb.sheets()[0]
+ for row in range(s.nrows):
+ this_row = []
+ for col in range(s.ncols):
+ val = s.cell_value(row, col)
+ if isinstance(val, unicode):
+ val = val.encode('utf8')
+ if isinstance(val, float):
+ val = str(val)
+ this_row.append(val)
+ wbcsv.writerow(this_row)