Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove emojis from a dataframe?

I know that

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'))

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'''

like image 223
maybeyourneighour Avatar asked Sep 02 '25 14:09

maybeyourneighour


1 Answers

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'))
like image 65
ivallesp Avatar answered Sep 05 '25 05:09

ivallesp