2014-11-20 36 views
1

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

table.place.unique() 


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

它有Unicode字符串在你的程序是件好事!当您写入文件时,您可以指定一个编码,例如'table.to_csv( '/路径/ FILE.CSV',编码= 'UTF8')'。默认编码是ASCII。 – bernie 2014-11-20 23:33:35

回答

1
>>> 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) 
>>> 
相关问题