i have text file with data looking like this (a block of vertical columns with the id's and their corresponding variables). The set of variables is the same but it depends, some id's has more than one attribute for same variable, some doesnt have a certain variable so it is not exactly the set of variable for each id. Below an example of the first id's.(a vertical column )
|uid: zi | |mail: ab | |aglnPersonStatus: O | |aglnMailStatus: n | |aglnMailAlias: D| |aglnMailAlias: e| |aglnMailEffectiveAddr: z| |uid: k | |mail: c | |aglnPersonStatus: O | |aglnMailStatus: n | |aglnMailAlias: o | |aglnMailEffectiveAddr: k |
A more clear image of the text file: enter image description here I used python to transform it into a dataframe:
import collections
import pandas as pd
from collections import defaultdict as dd
with open ('table.txt', 'r')as f:
text_list=[r.strip() for r in f.readlines() if r.strip()]
text_list=[x.split(': ') for x in text_list]
data= dd(list)
for text in text_list:
data[text[0]].append(text[1])
df=pd.DataFrame.from_dict(data, orient='index')
df= df.transpose()
it gave me the result below presented in the image which is false, the first id has same variable with two attributes, but clearly his mail transposed to the second id instead.The second id thus lost his actual value that got transposed into the following id and so on. I want to group for the same id the attribute(s) for each corresponding variable.