Answers for "add lists as a columns to a csv file"

0

add lists as a columns to a csv file

import pandas as pd

list1 = [1, 2, 3]
list2 = [4, 5, 6]
list3 = [7, 8, 9]

df = pd.DataFrame(list(zip(*[list1, list2, list3]))).add_prefix('Col')

df.to_csv('file.csv', index=False)

print(df)

   Col0  Col1  Col2
0     1     4     7
1     2     5     8
2     3     6     9
Posted by: Guest on July-04-2021

Code answers related to "add lists as a columns to a csv file"

Python Answers by Framework

Browse Popular Code Answers by Language