Created
July 3, 2015 10:03
-
-
Save c7h/e0aa37201f255fd5e92a to your computer and use it in GitHub Desktop.
CSV DictWriter Example
This file contains 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
__author__ = 'Christoph Gerneth' | |
from csv import DictWriter | |
from random import randrange | |
filename = 'data.csv' | |
label = ['x-axis', 'y-axis'] | |
with open(filename, 'w') as f: | |
csvw = DictWriter(f, fieldnames=label) | |
csvw.writeheader() | |
for i in range(200): | |
randomint = randrange(1,20)+i | |
csvw.writerow({'x-axis': i, 'y-axis': randomint}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
data.csv [part]