Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 数据帧替换_Python - Fatal编程技术网

Python 数据帧替换

Python 数据帧替换,python,Python,Pandas和python新手,对在整个数据帧中替换多个unicode字符有疑问。使用python 2.7并从excel工作表导入。我的愿望是用ascii等效字符替换所有非ascii字符,或者什么都不替换 示例: 幕府日语2013年1月1日 u'COMFORT套房酒店\xa0STONE MOUNTAIN' 这是可行的,但很麻烦: rawdf = rawdf["Account_Name"].str.upper().str.replace(u'\u2013', ' ').str.replace(u'

Pandas和python新手,对在整个数据帧中替换多个unicode字符有疑问。使用python 2.7并从excel工作表导入。我的愿望是用ascii等效字符替换所有非ascii字符,或者什么都不替换

示例:
幕府日语2013年1月1日 u'COMFORT套房酒店\xa0STONE MOUNTAIN'

这是可行的,但很麻烦:

rawdf = rawdf["Account_Name"].str.upper().str.replace(u'\u2013', ' ').str.replace(u'\xa0', '-') + "|" + rawdf["COID"].str.upper()
这不起作用:

rawdf = rawdf.replace(u'\u2013', ' ')

您可以像这样进行编码/解码循环:

rawdf["Account_Name"].str..encode('ascii', 'ignore').str.decode('ascii')

使用“忽略”会删除ascii中无法表示的字符。中间表示是字节,因此我们需要再次将其编码回字符串。

感谢您的建议,但现在由于忽略,您提到的字符被删除。我真的需要换一个。下游流程需要比较原始集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集集。目前,这种差异是由这些独特的字符造成的。其他想法?你可以用“替换”来代替,它会保留角色的位置,并用“?”来填充它。