如何在 pandas.DataFrame 中添加表情符号

How to add emoji in a pandas.DataFrame

如何在数据框中添加表情符号?

import pandas as pd

list_emoji_found = {
 ':)': 12248,
 ':0': 88724,
 ':jabber:': 692,
 '8)': 719,
 ':-)': 351
}

#convert to series
s = pd.Series(list_emoji_found);
#convert to DataFrame
s = pd.DataFrame({'emoji':s.index, 'count':s.values})
s

Returns:

import emoji # Needs 'pip install emoji'

s['icons'] = s['emoji'].apply(lambda x: emoji.emojize(x))

Returns:

我的预期结果应该有第三列(图标)和字符串的表情符号表示。

  1. 您正在使用 non-existent 个表情符号。没有 ':)':jabber: 表情符号。您可以找到 "official" 个表情符号 here
  2. 您应该在 lambda 中使用 use_aliases=True。这是示例:
import pandas as pd

list_emoji_found = {
 ':)': 12248,
 ':heart:': 88724,
 ':relaxed:': 692,
 ':gun:': 719,
 ':-)': 351
}

s = pd.Series(list_emoji_found);
s = pd.DataFrame({'emoji':s.index, 'count':s.values})
s['icons'] = s['emoji'].apply(lambda x: emoji.emojize(x, use_aliases=True))
s

会return:

    emoji       count   icons
0   :)          12248   :)
1   :heart:     88724   ❤
2   :relaxed:   692     ☺
3   :gun:       719     
4   :-)         351     :-)