问题
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'''
回答1:
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'))
来源:https://stackoverflow.com/questions/57514169/how-can-i-remove-emojis-from-a-dataframe