I have a dataframe in the following structure:
cNames | cValues | number
[a,b,c] | [1,2,3] | 10
[a,b,d] | [55,66,77]| 20
I would like to transpose - create columns from the names in cNames.
But I can't manage to achieve this with transpose because I want a column for each value in the list.
The needed output:
a | b | c | d | number
1 | 2 | 3 | NaN | 10
55 | 66 | NaN | 77 | 20
How can I achieve this result?
Thanks!
The code to create the DF:
d = {'cNames': [['a','b','c'], ['a','b','d']], 'cValues': [[1,2,3],
[55,66,77]], 'number': [10,20]}
df = pd.DataFrame(data=d)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…