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

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
@Sereger13

Sereger13 commented Nov 18, 2015

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
...

@jreback

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback Nov 18, 2015

Contributor

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'
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 jreback added this to the Next Major Release milestone Nov 18, 2015

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

@jreback

This comment has been minimized.

Show comment
Hide comment
@jreback

jreback Nov 20, 2015

Contributor

closed by #11649

Contributor

jreback commented Nov 20, 2015

closed by #11649

@jreback jreback closed this Nov 20, 2015

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

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 pandas-dev#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, pandas-dev#11611
  DOC: Clarify foramtting
  BUG: pandas-dev#11638 return correct dtype for int and float
  BUG: pandas-dev#11637 fix to_csv incorrect output.
  DOC: sponsor notice
  BUG: indexing with a range , pandas-dev#11652
  Fix link to numexpr
  ENH: fixup tilde expansion, xref pandas-dev#11438
  ENH: tilde expansion for write output formatting functions, pandas-dev#11438
  DOC: fix up doc-string creations in generic.py
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment