如何从数据框中删除表情符号? [英] How can I remove emojis from a dataframe?

查看:29
本文介绍了如何从数据框中删除表情符号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道

test = []
for item in my_texts:
    test.append(item.encode('ascii', 'ignore').decode('ascii'))

从列表中删除表情符号.但是,如何从数据框中删除表情符号?当我尝试

removes emojis from a list. But how can I remove emojis from a dataframe? When I try

a = []
for item in goldtest['Text']:
    a.append(item.encode('ascii', 'ignore').decode('ascii'))

我仅获得goldtest的最后一个条目.当我在整个数据帧上尝试代码时,出现"AttributeError:'DataFrame'对象没有属性'encode'"

I get only the last entry of goldtest. When I try the code on the whole dataframe, I get ''AttributeError: 'DataFrame' object has no attribute 'encode'''

推荐答案

这与熊猫等效.它逐列操作.

This would be the equivalent code for pandas. It operates column by column.

df.astype(str).apply(lambda x: x.str.encode('ascii', 'ignore').str.decode('ascii'))

这篇关于如何从数据框中删除表情符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆