May-23-2017, 02:06 PM
My bank statement is a CSV with two different delimiters namely '|' and ’;' . I wanted to write a script, that makes me a 2-dimensional list (lines+rows) of the values to be able to put the values in the same order in every row – some lines (where tings are paid in other currencies have an additional row[2] as you can see in the first line in my testfile – the lines vary in length.
I wanted to delete this elements in order to have a nice CSV with the correct values under each other.
######Testfile##############
XY234567890123223423;INSURANCE Corpxy |USD 8,42|74921027234234523507320;03.04.2017;28.03.2017;-8,42;EUR
XY234567890123223423;AIRBNB * HM4R3TCPM 332-048-3753|743133023423423400822139045;03.04.2017;29.03.2017;-67,00;EUR
I wanted to delete this elements in order to have a nice CSV with the correct values under each other.
######Testfile##############
XY234567890123223423;INSURANCE Corpxy |USD 8,42|74921027234234523507320;03.04.2017;28.03.2017;-8,42;EUR
XY234567890123223423;AIRBNB * HM4R3TCPM 332-048-3753|743133023423423400822139045;03.04.2017;29.03.2017;-67,00;EUR
import csv, pprint
fpath = './Testlist.csv'
def readfile():
records = []
with open(fpath, 'r') as originalfile:
rawdata1 = originalfile.read()
print(rawdata1)
rawdata1 = str(rawdata1).replace("|",";")
print(rawdata1)
csvreader = csv.reader(rawdata1, delimiter=';')
for row in csvreader:
records.append(row)
print(records)
def printlist(records):
for elem in records:
print(elem)
records = readfile()
