Skip to content

Cannot save DataFrame with unicode to CSV #705

@jtbates

Description

@jtbates
In [1]: from pandas import DataFrame
In [2]: df = DataFrame({u'c/\u03c3':[1,2,3]})
In [3]: df.to_csv('test')
---------------------------------------------------------------------------
UnicodeEncodeError                        Traceback (most recent call last)
.../<ipython-input-3-9b2e5ea53beb> in <module>()
----> 1 df.to_csv('test')

.../lib/python2.7/site-packages/pandas-0.7.0.dev_88fcac5-py2.7-macosx-10.4-x86_64.egg/pandas/core/frame.pyc in to_csv(self, path, sep, na_rep, cols, header, index, index_label, mode, nanRep)
    891                     # given a string for a DF with Index

    892                     index_label = [index_label]
--> 893                 csvout.writerow(list(index_label) + list(cols))
    894             else:
    895                 csvout.writerow(cols)

UnicodeEncodeError: 'ascii' codec can't encode character u'\u03c3' in position 2: ordinal not in range(128)

I think this should be separate from #680. The CSV issue is also mentioned in this comment on bug #300.

Metadata

Metadata

Assignees

No one assigned

    Labels

    UnicodeUnicode strings

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions