无法从pandas中的列名中删除unicode char

6 python unicode pandas

我在pandas dataframe中读过一个csv文件,我试图从列名中删除unicode char u但没有运气.

fl.columns
Index([ u'time', u'contact', u'address'], dtype='object')

headers=[ 'time', 'contact', 'address']
fl=pandas.read_csv('file.csv',header=None,names=headers)
Run Code Online (Sandbox Code Playgroud)

还是不行

fl.columns
Index([ u'time', u'contact', u'address'], dtype='object')
Run Code Online (Sandbox Code Playgroud)

即使重命名也不起作用

fl.rename(columns=lambda x:x.replace(x,x.value.encode('ascii','ignore')),inplace=True)
fl.columns
Index([ u'time', u'contact', u'address'], dtype='object')
Run Code Online (Sandbox Code Playgroud)

任何人都可以告诉我为什么会发生这种情况以及如何解决这个问题?谢谢.

pau*_*ip3 5

如果您确实需要删除u(因为这只是显示问题),则可以执行以下非常肮脏的技巧

from pandas import compat

compat.PY3 = True

df.columns
Index(['time', 'contact', 'address'], dtype='object')
Run Code Online (Sandbox Code Playgroud)