Skip to content
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

ENH: specify header=['list', 'of', 'headers'] in DataFrame.write_csv() #921

Closed
brentp opened this issue Mar 15, 2012 · 1 comment
Closed
Labels
Enhancement IO Data IO issues that don't fit into a more specific label
Milestone

Comments

@brentp
Copy link

brentp commented Mar 15, 2012

As with R's write.table col.names which can take a list of column headers to output instead of the
headers.

here's a start, though I'm unsure about hwo it interacts with the index label stuff.

diff --git a/pandas/core/frame.py b/pandas/core/frame.py
index 248a4e9..8c93488 100644
--- a/pandas/core/frame.py
+++ b/pandas/core/frame.py
@@ -13,7 +13,7 @@ labeling information

 # pylint: disable=E1101,E1103
 # pylint: disable=W0212,W0231,W0703,W0622
-
+import collections
 from itertools import izip
 from StringIO import StringIO
 import csv
@@ -889,7 +889,9 @@ class DataFrame(NDFrame):
             cols = self.columns

         series = self._series
-        if header:
+        if isinstance(header, collections.Iterable):
+            writer.writerow([h or '' for h in header])
+        elif header:
             if index:
                 # should write something for index label
                 if index_label is None:
@wesm
Copy link
Member

wesm commented Jun 25, 2012

This has been implemented in git master for 0.8.0, thanks all!

@wesm wesm closed this as completed Jun 25, 2012
yarikoptic added a commit to neurodebian/pandas that referenced this issue Jun 30, 2012
* commit 'v0.8.0rc2-26-g76c6351': (42 commits)
  BUG/TST: typo caused read_csv to lose index name pandas-dev#1536
  BUG: incorrect tick label positions pandas-dev#1531 (zooming is still wrong)
  ENH: register converters with matplotlib for better datetime convesion
  ENH: handle datetime.date in Period constructor
  DOC: small doc for pandas-dev#1450
  BUG: repr of pre-1900 datetime64 values in a DataFrame column close pandas-dev#1518
  BUG: workaround vstack/concat bug in numpy 1.6 pandas-dev#1518
  DOC: lreshape docstring, release note
  ENH: experimental lreshape function
  BUG: plotting DataFrame with freq with offset
  BUG: DataFrame plotting with inferred freq
  BUG: timedelta.total_seconds only in 2.7 and 3.2
  DOC: release notes
  ENH: Add raise on conflict keyword to update
  DOC: release notes re: pandas-dev#921
  overload header keyword instead of extra col_aliases keyword
  ENH: column aliases for to_csv/to_excel pandas-dev#921
  ENH: handle weekly resampling via daily
  BUG: plot mixed frequencies pandas-dev#1517
  BUG/TST: plot irregular and reg freq on same subplot
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement IO Data IO issues that don't fit into a more specific label
Projects
None yet
Development

No branches or pull requests

2 participants