# Convert a repetitive list into Pandas Dataframe [closed]

How do you convert something like this:

A: 1
B: 2
C: 3
###
A: 5
B: 5
C: 6
###
A: 2
B: 5
C: 7


into a dataset where the first row would be the first section with

A as column-1 B as column-2 and C as column-3

so we get this:

 A B C
1 2 3
5 5 6
2 5 7


## closed as off-topic by Toros91, Pedro Henrique Monforte, oW_♦Apr 22 at 3:44

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "This question does not appear to be about data science, within the scope defined in the help center." – Toros91, Pedro Henrique Monforte, oW_
If this question can be reworded to fit the rules in the help center, please edit the question.

• How exactly is the initial data stored? List of dictionaries? – Ben Reiniger Apr 21 at 17:02
• It is stored as a plain text file – OcK Apr 21 at 17:15

If I understand this correctly your sequence is always 3 elements. Then you can do this:

a = ['A:1','B:2','C:3','A:5','B:5','C:6','A:2','B:5','C:7']
b = []
rep_len = 3

# Looping with step size equal to repetition length
for i in range(0,len(a),rep_len):

# Selecting a repetition length
c = a[i:i+rep_len]

# Extracting everything in after letter and colon and casting to integer
c = [int(x[2:]) for x in c]

# Append to a list of lists
b.append(c)

df = pd.DataFrame(b, columns=['A', 'B', 'C'])


Resulting in:

    A   B   C
0   1   2   3
1   5   5   6
2   2   5   7

• Exactly what I asked for - Thanks! – OcK Apr 21 at 18:11