everyone.
Below is the code I'm using to parse a text file:
import pandas as pd
tags = ['129','30','32','851','9730','9882']
rows = []
file = open('D:\\python\\redi_fix\\redi_august.txt','r')
content = file.readlines()
for line in content:
for message in line.split('\t'):
try:
row_dict = {}
tag,val = message.split('=')
if tag in tags:
row_dict[tag]=val
rows.append(row_dict)
except:
pass
Creating a pandas dataframe from rows yields the following result:
129 30 32 851 9730 9882
r170557 NaN NaN NaN NaN NaN
NaN ARCA NaN NaN NaN NaN
NaN NaN 100 NaN NaN NaN
r170557 NaN NaN NaN NaN NaN
NaN ARCA NaN NaN NaN NaN
NaN NaN 300 NaN NaN NaN
Looks like every value for a key is on a different row. The result I'm struggling to achieve is all values to be on the same row - see below for example:
129 30 32 851 9730 9882
r170557 ARCA 100 NaN NaN NaN
r170557 ARCA 300 NaN NaN NaN