Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
CSV DictWriter Example
__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})
@c7h

This comment has been minimized.

Copy link
Owner Author

commented Jul 3, 2015

data.csv [part]

x-axis,y-axis
0,9
1,6
2,11
3,18
4,22
5,15
6,24
7,14
8,23
9,27
10,17
11,24
12,14
13,20
14,22
15,31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.