Text Pattern into Data Frame

Question:

import pandas as pd
text = '''
12/2/2023
Deposit
USD
10
Complete
15/2/2023
Deposit
USD
15
Complete
'''
x = text.split()
y=pd.DataFrame(x)
print(y)

I want convert this into data frame with colums ‘date’,’txn_type’,’curr’,’Amt’,’status’, any suggestions

Asked By: Vinod R

||

Answers:

You can reshape the split text

x = np.array(text.split()).reshape(-1, 5)
y = pd.DataFrame(x, columns=['date','txn_type','curr','Amt','status'])
print(y)

        date txn_type curr Amt    status
0  12/2/2023  Deposit  USD  10  Complete
1  15/2/2023  Deposit  USD  15  Complete
Answered By: Ynjxsjmh
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.