Skip to content

Instantly share code, notes, and snippets.

@ap-Codkelden
Created September 14, 2015 14:32
Show Gist options
  • Save ap-Codkelden/7c5817ca61b0e26069b2 to your computer and use it in GitHub Desktop.
Save ap-Codkelden/7c5817ca61b0e26069b2 to your computer and use it in GitHub Desktop.
Parse CSV
import csv
STI = (83,87,18)
xl_db_file = 'f0809m.csv'
to_int = lambda x: float(x.replace(' ','').replace(',','.'))
def xlfmt_conv(row, len_row):
for k in range(3,len_row):
row[k] = to_int(row[k])
with open(xl_db_file, newline='\n') as csvfile:
spam = csv.reader(csvfile, delimiter=';', quotechar='"')
s=list(spam)
head = [' '.join(x).strip() for x in list(zip(s[6],s[7],s[8],s[9],s[10],s[11],s[12],))]
wrk_list = [sti for sti in s[13:] if (int(sti[0]) if sti[0].isdigit() else 0) in STI]
len_row = len(wrk_list[0])
for i in wrk_list:
i = xlfmt_conv(i, len_row=len_row)
wrk_list.reverse()
wrk_list.append(head)
wrk_list.reverse()
transp = []
for a in range(len_row):
transp.append([])
for i in range(len(wrk_list)):
for j in range(len_row):
transp[j].append(wrk_list[i][j])
for i in range(5):
print(transp[i],'\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment