DataFrame.to_csv() produces wrong results when mixed-type columns are specified #11637

Closed
Sereger13 opened this Issue Nov 18, 2015 · 2 comments

Comments

Projects
None yet
2 participants

This used to work OK in version 0.15 but stopped working in versions 0.16+.

import pandas as pd
df = pd.DataFrame({0: ['a', 'b', 'c'],
                   1: ['aa', 'bb', 'cc']})
df['test'] = 'txt'
df.to_csv('/home/temp/df.csv', columns=['test', 0, 1])

The following output is produced (values from columns 0 and 1 are missing):

,test,0,1
0,txt,,
1,txt,,
2,txt,,

Replacing 'test' with an integer value or skipping the columns argument works fine.

INSTALLED VERSIONS

commit: None
python: 2.7.9.final.0
python-bits: 64
OS: Linux
OS-release: 2.6.18-238.9.1.el5
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US

pandas: 0.17.0
...

Contributor

jreback commented Nov 18, 2015

yeh should probably work, pull-requests to fix are welcome

In [11]: df.to_csv()
Out[11]: ',0,1,test\n0,a,aa,txt\n1,b,bb,txt\n2,c,cc,txt\n'

In [12]: df.to_csv(columns=['test',0,1])
Out[12]: ',test,0,1\n0,txt,,\n1,txt,,\n2,txt,,\n'

jreback added this to the Next Major Release milestone Nov 18, 2015

@jreback jreback modified the milestone: 0.17.1, Next Major Release Nov 19, 2015

Contributor

jreback commented Nov 20, 2015

closed by #11649

jreback closed this Nov 20, 2015

@yarikoptic yarikoptic added a commit to neurodebian/pandas that referenced this issue Dec 3, 2015

@yarikoptic yarikoptic Merge tag 'v0.17.1' into debian
Version 0.17.1

* tag 'v0.17.1': (168 commits)
  add nbviewer link
  Revert "DOC: fix sponsor notice"
  DOC: a few touchups
  DOC: fix sponsor notice
  DOC: warnings and remove HTML
  COMPAT: compat of scalars on all platforms, xref #11638
  DOC: fix build errors/warnings
  DOC: whatsnew edits
  DOC: fix link syntax
  DOC: update release.rst / whatsnew edits
  BUG: fix col iteration in DataFrame.round, #11611
  DOC: Clarify foramtting
  BUG: #11638 return correct dtype for int and float
  BUG: #11637 fix to_csv incorrect output.
  DOC: sponsor notice
  BUG: indexing with a range , #11652
  Fix link to numexpr
  ENH: fixup tilde expansion, xref #11438
  ENH: tilde expansion for write output formatting functions, #11438
  DOC: fix up doc-string creations in generic.py
  ...
9b2e35f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment