Created
May 3, 2016 11:07
-
-
Save g33klord/1efe551ef896ded01f74b2e3f8e9ef4b to your computer and use it in GitHub Desktop.
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
rows = [] | |
with open('large.csv', 'rb') as f: | |
csvrows = csv.DictReader(f) | |
for line in csvrows: | |
rows.append(line) | |
chunks = [rows[x:x+45000] for x in xrange(0, len(rows), 45000) ] | |
for i, chunk in enumerate(chunks): | |
print 'Chunk: {}/{}'.format(i, len(chunks)) | |
with open(str(i)+'.csv', 'wb') as f: | |
dictwriter = csv.DictWriter(f, fieldnames=chunk[0].keys()) | |
dictwriter.writeheader() | |
for c in chunk: | |
dictwriter.writerow(c) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment