Skip to content

Instantly share code, notes, and snippets.

@hayd
Created April 20, 2015 19:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hayd/22020d3fef347229728b to your computer and use it in GitHub Desktop.
Save hayd/22020d3fef347229728b to your computer and use it in GitHub Desktop.
appending to csv
def append_frame(f='foo.csv', df=df, keep_open=False, n=1000):
if keep_open:
with open(f, mode='a') as f_:
for i in xrange(n):
df.to_csv(f_, mode='a')
else:
for i in xrange(n):
df.to_csv(f, mode='a')
os.remove(f)
# Try these for some (increasing values of n):
%timeit append_frame(keep_open=True, n=100000)
%timeit append_frame(keep_open=False, n=100000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment