Skip to content
This repository

Support different delimiters for to_csv #244

Closed
wants to merge 3 commits into from

2 participants

Luca Beltrame Wes McKinney
Luca Beltrame

This pull requests implements delimter support into to_csv. A number of analysis tools expects TSV files rather than CSV files, and this is a simple solution to the problem.

The delimiter parameter is by default ",", hence there are no side effects with existing code.

Wes McKinney
Owner

thanks! merged it into master

Wes McKinney wesm closed this October 19, 2011
Wes McKinney
Owner

i'm going to change the argument name to sep instead of delimiter to conform with read_csv and read_table

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 4 additions and 2 deletions. Show diff stats Hide diff stats

  1. 6  pandas/core/frame.py
6  pandas/core/frame.py
@@ -469,7 +469,7 @@ def to_sparse(self, fill_value=None, kind='block'):
469 469
                                default_fill_value=fill_value)
470 470
 
471 471
     def to_csv(self, path, nanRep='', cols=None, header=True,
472  
-              index=True, index_label=None, mode='w'):
  472
+              index=True, index_label=None, mode='w', delimiter=","):
473 473
         """
474 474
         Write DataFrame to a comma-separated values (csv) file
475 475
 
@@ -489,9 +489,11 @@ def to_csv(self, path, nanRep='', cols=None, header=True,
489 489
             `header` and `index` are True, then the index names are used. A
490 490
             sequence should be given if the DataFrame uses MultiIndex.
491 491
         mode : Python write mode, default 'w'
  492
+        delimiter : character, default ","
  493
+            Field delimiter for the output file.
492 494
         """
493 495
         f = open(path, mode)
494  
-        csvout = csv.writer(f, lineterminator='\n')
  496
+        csvout = csv.writer(f, lineterminator='\n', delimiter=delimiter)
495 497
 
496 498
         if cols is None:
497 499
             cols = self.columns
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.