chattrat423 chattrat423 - 1 year ago 169
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;


Answer Source

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']].

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download