Skip to content

Instantly share code, notes, and snippets.

@kelvinn
Created November 21, 2013 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kelvinn/7576994 to your computer and use it in GitHub Desktop.
Save kelvinn/7576994 to your computer and use it in GitHub Desktop.
This gist shows how to take the timeline backup from Twitter and transform it into a dictionary using the headers as keys. For example, if the CSV file looked had two columns, col1 and col2, it would result in list that looked like: [{'col1': 'hello', 'col2': 'world'}, {'col1': 'bye', 'col2': 'world'}] It also converts the format used by Twitter…
import csv
from dateutil import parser
qs_list = []
with open('C:\\Users\\username\\Desktop\\tweets.csv', 'rb') as csvfile:
qsreader = csv.reader(csvfile, delimiter=',', quotechar='"')
header = qsreader.next()
for row in qsreader:
d = parser.parse(row[6])
row[6] = d.isoformat()
qs_list.append(dict(zip(header,row)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment