Skip to content

improving df.to_csv performance #7147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

michaelaye
Copy link
Contributor

This is a WIP and discuss PR 🚧 for #3186
Adding small Writer class to have short-lived self.writer in CSVFomatter just for the header line. It is closed after the header was written.
Adding new lib.pyx function write_csv_rows_fast that manages file open/close on its own with self.path_or_buf from CSVFormmatter.
Current speed-up is factor 2.5 compared to before. Possibly the fprintf for each item is inefficient, but I thought as fprintf is buffered (in contrast to write) it can't be too bad. Any suggestions what I'm doing horribly wrong?

…rows_fast into lib.pyx that manages file open/close on its own with self.path_or_buf from CSVFormmatter.
@@ -1165,6 +1165,20 @@ def save(self):
if self.encoding is not None:
writer_kwargs['encoding'] = self.encoding
self.writer = com.UnicodeWriter(f, **writer_kwargs)

elif self.engine == 'fast':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls add a loop around some of the tests, so that each are tested with each engine e.g. [None,fast'] (I think the default is None), we should remove the 'python' engine (separate issue). Of course later need to add logic / tests to deal with certain data that maybe can't be written via fast engine

…ce. Taking care of float, int and string dtypes.
@jreback
Copy link
Contributor

jreback commented Jan 18, 2015

closing for now. pls reopen if you want to update.

@jreback jreback closed this Jan 18, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO CSV read_csv, to_csv Output-Formatting __repr__ of pandas objects, to_string Performance Memory or execution speed performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants