Skip to content

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

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
Sereger13 opened this issue Nov 18, 2015 · 2 comments
Closed
Labels
Bug IO CSV read_csv, to_csv Output-Formatting __repr__ of pandas objects, to_string
Milestone

Comments

@Sereger13
Copy link
Contributor

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
Copy link
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 Bug Output-Formatting __repr__ of pandas objects, to_string Difficulty Novice IO CSV read_csv, to_csv labels Nov 18, 2015
@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 pushed a commit that referenced this issue Nov 20, 2015
@jreback
Copy link
Contributor

jreback commented Nov 20, 2015

closed by #11649

@jreback jreback closed this as completed Nov 20, 2015
yarikoptic added a commit to neurodebian/pandas that referenced this issue Dec 3, 2015
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
Labels
Bug IO CSV read_csv, to_csv Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

No branches or pull requests

2 participants