Skip to content

Instantly share code, notes, and snippets.

@c7h
Created July 3, 2015 10:03
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 c7h/e0aa37201f255fd5e92a to your computer and use it in GitHub Desktop.
Save c7h/e0aa37201f255fd5e92a to your computer and use it in GitHub Desktop.
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
Copy link
Author

c7h 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