1

How does one remove 'u'(unicode) from all the values in a column in a DataFrame?

table.place.unique()


array([u'Newyork', u'Chicago', u'San Francisco'], dtype=object)
1
  • 1
    It's a good thing to have Unicode strings in your program! When you write to a file you can specify an encoding, e.g. table.to_csv('/path/file.csv',encoding='utf8'). The default encoding is ASCII. Nov 20, 2014 at 23:33

1 Answer 1

2
>>> df = pd.DataFrame([u'c%s'%i for i in range(11,21)], columns=["c"])
>>> df
     c
0  c11
1  c12
2  c13
3  c14
4  c15
5  c16
6  c17
7  c18
8  c19
9  c20
>>> df['c'].values
array([u'c11', u'c12', u'c13', u'c14', u'c15', u'c16', u'c17', u'c18',
       u'c19', u'c20'], dtype=object)
>>> df['c'].astype(str).values
array(['c11', 'c12', 'c13', 'c14', 'c15', 'c16', 'c17', 'c18', 'c19', 'c20'], dtype=object)
>>>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.