How to create a spreadsheet file (CSV) with two columns in Python

1 Answer

0 votes
import csv

data = {"alex(A2)": "alex@email.com(B2)", "alice(A3)": "alice@email.com(B3)"}

with open('d:\data.csv', 'w') as csv:
    columnsTitle = "name(A1), email(B1)\n"
    csv.write(columnsTitle)

    for key in data.keys():
        name = key
        email = data[key]
        row = name + "," + email + "\n"
        csv.write(row)


'''
run:

data.csv
--------
name(A1), email(B1)
alex(A2),alex@email.com(B2)
alice(A3),alice@email.com(B3)

'''

 



answered Jun 28, 2018 by avibootz
edited Jun 29, 2018 by avibootz

Related questions

1 answer 181 views
1 answer 256 views
1 answer 215 views
1 answer 236 views
1 answer 191 views
...