У меня есть фрейм данных pandas, который выглядит так:
A
B
[1,2]
X
[3,4]
Да
Я хочу, чтобы это выглядело так:
A_0
A_1
B< /th>
1
< td>2
X
3
4
Да
Как лучше всего это сделать?
Я пробовал так:
col = "A"
max_len = df.apply(lambda row: len(row[col_to_expand]), axis = 1).max() # gets max length of the list
labels = [ col + "_" + str(i) for i in range(max_len) ] #create output labels
df[labels] = df[col]
Подробнее здесь: https://stackoverflow.com/questions/786 ... le-columns