I have below Lists
Number = [[1],[2],[3],[4],[6]]
L1 = ['A','B','C','D','E']
L2 = [100, 55, 315, 68, 23]
L3 = ['18%','105','56%','12%','4%']
I wanted to Zip all the lists and create a DataFrame
. I used the below code and successfully able to do it.
for n, l1, l2, l3 in zip(Number,L1,L2, L3):
n.insert(1,l1)
n.insert(2,l2)
n.insert(3,l3)
df = pd.DataFrame(Number, columns=['Number','Name', 'Value', 'Score'])
print(df)
+---+--------+------+-------+-------+
| | Number | Name | Value | Score |
+---+--------+------+-------+-------+
| 0 | 1 | A | 100 | 18% |
+---+--------+------+-------+-------+
| 1 | 2 | B | 55 | 105 |
+---+--------+------+-------+-------+
| 2 | 3 | C | 315 | 56% |
+---+--------+------+-------+-------+
| 3 | 4 | D | 68 | 12% |
+---+--------+------+-------+-------+
| 4 | 6 | E | 23 | 4% |
+---+--------+------+-------+-------+
Since there is only 4 lists in this example. Easily we can type manually for n, l1, l2, l3 in zip(Number,L1,L2, L3):
and type individual insert
functions.
Now my question is, what if there is many lists (say 15)? is there a pythonic
way of doing this?