pandas 如何从 DataFrame 的列中的所有值中删除“u”(unicode)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27051306/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 22:41:32  来源:igfitidea点击:

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

unicodepandasipython

提问by tintin

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

如何'u'(unicode)从 a 中的列中的所有值中删除DataFrame

table.place.unique()


array([u'Newyork', u'Chicago', u'San Francisco'], dtype=object)

回答by Kracit

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