python - Printing Pandas Columns With Unicode Characters -
i have pandas dataframe single column contains unicode encoded name.
import pandas pd no_unicode = pd.series(['steve', 'jason', 'jake']) yes_unicode = pd.series(['tea', 'caf\xe9', 'beer']) var_names = dict(no_unicode = no_unicode, yes_unicode = yes_unicode) df = pd.dataframe(var_names) print(df)
i can print dataframe in ipython fine, error when try print dataframe in sublimetext (using py3).
unicodeencodeerror: 'ascii' codec can't encode character '\xe9' in position 73: ordinal not in range(128)
i have searched high , low solution (and learned lot unicode in process) cannot figure out how print dataframe while in sublimetext.
any appreciated.
there useful function u
in pandas.compat
, make values in unicode.:
in [26]: import pandas pd pandas.compat import u no_unicode = pd.series(['steve', 'jason', 'jake']) #yes_unicode = pd.series(['tea', 'caf\xe9', 'beer']) yes_unicode = pd.series(map(u,['tea', 'caf\xe9', 'beer'])) var_names = dict(no_unicode = no_unicode, yes_unicode = yes_unicode) df = pd.dataframe(var_names) print(df) no_unicode yes_unicode 0 steve tea 1 jason café 2 jake beer [3 rows x 2 columns]
Comments
Post a Comment