I have a list where the number of items between a 'SUMMARY' element and the next one is not fixed
list = ['SUMMARY - Dec 2013', 'Person1', 'None', 'None', '10', 'SUMMARY - Dec 2013', 'Person2', '20', 'SUMMARY - Jan 2014', 'Person3', 'None']
What I'm trying to achieve is to transform the list to a dataframe where each row starts with a 'SUMMARY' element.
I've used
match = []
match.append([n for n, l in enumerate(list) if l.startswith('SUMMARY')])
with output [[0, 5, 8]]
to get the indexes of the items that contain 'SUMMARY', and I would like each row of my dataframe to start with the corresponding items whose indexes are included in match
. In this case, match has 3 elements, so I would like my dataframe to have 3 rows and the following structure:
'SUMMARY - Dec 2013', 'Person1', 'None', 'None', '10'
'SUMMARY - Dec 2013', 'Person2', '20', NA, NA
'SUMMARY - Jan 2014', 'Person3', 'None', NA, NA
Basically, when the number of items for a specific row is smaller than the number of max columns, the rest gets filled with NA/NaN.