How to remove emoji in dataframe?

Question:

Hi I have a dataframe below and I wanna remove the emoji

col1    col2
-------------
Hi   |  14

hey  |  8
-------------

I have tried using the code below to remove emoji

However, the error message shows remove_emoji() takes 0 positional arguments but 1 was given

I would like to know if there’s anything wrong to my code and if there’s other way please let me know.
Thank u very much.

def remove_emoji():
    for text in df["col1"]:
        return emoji.replace_emoji(text, replace="")

df["col1"] = df["col1"].apply(remove_emoji)
Asked By: B34061186

||

Answers:

If it’s more clear, df['col1'].apply(remove_emoji) is equivalent to
df['col1'].apply(lambda x: remove_emoji(x)) so your function should have a parameter x and I’m assuming you don’t need that for loop because your function will be applied on each item of your series (df['col1']) individually.
So your function should just be :

def remove_emoji(text):
    return emoji.replace_emoji(text, replace="")
Answered By: unknown person
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.