Pandas:将Unicode字符串转换为字符串

3

我有一个数据框,其中有两列是Unicode值。我需要将它们转换为字符串。我尝试使用df.domain.astype(str),但它返回的是Unicode字符串。我该怎么办?数据看起来像这样(我需要转换其中的任一列)

domain       search_term
vk.com           None
facebook.com     None
yandex.ru        снять квартиру
locals.ru        None
yandex.ru        снять квартиру без посредников в Москве
avito.ru         None

抱歉,您是在询问 df['str_col'].str.decode('utf-8') 吗?另外,您能否发布原始数据和代码以避免歧义。 - EdChum
@EdChum 这并没有帮助。 - NineWasps
1个回答

2
这对您有帮助吗?
for col in types[types=='unicode'].index:
    df[col] = df[col].astype(str)

或者:

for col in types[types=='unicode'].index:
     df[col] = df[col].apply(lambda x: x.encode('utf-8').strip())

你能说一下,我可以在这个字符串中使用它吗?f.edge(group['subdomain'].iloc[i], group['subdomain'].iloc[i+1] - NineWasps

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接