网站更新内容:请访问: https://bigdata.ministep.cn/

pandas 的unicode转换成中文

需要将unicode转换成中文

import pandas as pd 
data = [{'ds': 20200621, 'tags_name': '(\\u6253\\u91ce")"'},
 {'ds': 20200621, 'tags_name': '(10-19\\u5e01""'},
 {'ds': 20200621, 'tags_name': '(10-19\\u5e01")"'},
 {'ds': 20200621, 'tags_name': '(11-20\\u5e01""'},
 {'ds': 20200621, 'tags_name': '(11-20\\u5e01")"'}]
df = pd.DataFrame(data)
df['tags_name'] = df['tags_name'].str.replace(' ','')
df['tags_name'] = df['tags_name'].str.replace(r'U',r'u',regex=True)
df['tags_name'] = df['tags_name'].apply(lambda x:x.encode('utf-8').decode('unicode_escape'))

image

难点:

  1. 将unicode转换成中文: x.encode('utf-8').decode('unicode_escape')
  2. python需要将\U 替换成 \u
posted @ 2022-02-16 15:13  ministep88  阅读(457)  评论(0)    收藏  举报
网站更新内容:请访问:https://bigdata.ministep.cn/