I have an text file as below format. I want to read through all the records in the file and output in a dataframe.
NEW ACCOUNT ABC COMPANY 00123
CCY/BALANCE USD 3,600
ACCOUNT APPROVAL ABC COMPANY 00123
NEW ACCOUNT BBC COMPANY 00124
CCY/BALANCE USD 5,600
Expected output:
TRAN DESCRIPTION CUSTOMER NAME A/C NO. CCY BALANCE
NEW ACCOUNT ABC COMPANY 00123 USD 3,600.00
ACCOUNT APPROVAL ABC COMPANY 00123
NEW ACCOUNT BBC COMPANY 00124 USD 5,600.00
There will be two types of trans description. Code I am trying as below, but it only works for one line of the text file. How can I modify to read through all the records in the files? Thanks!
text = ‘NEW ACCOUNT ABC COMPANY 00123’
sep = ' '
lst = text.split(sep)
while(' ' in lst) :
lst.remove(' ')
lst = np.array(lst).reshape(1,3)
df = pd.DataFrame(lst,columns =['TRAN DESCRIPTION', 'CUSTOMER NAME', 'A/C NO.'])
