chattrat423 chattrat423 - 2 months ago 13x
Python Question

Convert List to Rows

What is an efficient way to convert a list into separate elements in python?

I have a dataset that looks like this;


I would like to reshape the data so that each student/score has its own row;



You could use a list comprehension, like this:

data = ['StudentA','80','94','93']
res = [[data[0], x] for x in data[1:]]

This sets res to [['StudentA', '80'], ['StudentA', '94'], ['StudentA', '93']].