Created
August 27, 2024 19:13
-
-
Save birkin/ac10a6999cb0649d1a2cbcaaf1bda2d0 to your computer and use it in GitHub Desktop.
convert two lines of data to tsv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### convert the two rows of data to a tsv file using the python csv module | |
import csv | |
original_two_lines = [ | |
['id', 'jacket_id', 'firstname', 'lastname', 'shortID', 'title', 'pub_date', 'image', 'role', 'dept', 'dept2', 'dept3', 'active', 'created_at', 'updated_at'], | |
['10', '10', 'First', 'Last', 'flast', 'the long title', '2015', 'flast.jpg', 'author', 'Political Science', 'International and Public Affairs', 'y', '', '', ''] | |
] | |
with open('data.tsv', 'w') as tsvfile: | |
writer = csv.writer(tsvfile, delimiter='\t') | |
writer.writerows(original_two_lines) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment