将包含表情符号的JSON读取到Pandas Dataframe中

时间:2019-03-26 02:08:24

标签: python pandas emoji

我收到类似UTF-8编码的JSON文件

[
    {
        "FieldA": "regular string 1",
        "FieldB": "... \ud83e\uddc0"
    },
    {
        "FieldA": "regular string 2",
        "FieldB": "... \ud83d\ude0d"
    }
]

我尝试使用来阅读

df = pd.read_json(file_path, orient="columns", encoding="utf-8")

但是我看不到表情符号。有什么建议吗?

谢谢。

1 个答案:

答案 0 :(得分:0)

您可以使用jsonjson_normalize

import json 
from pandas.io.json import json_normalize

j = [
    {
        "FieldA": "regular string 1",
        "FieldB": "... \ud83e\uddc0"
    },
    {
        "FieldA": "regular string 2",
        "FieldB": "... \ud83d\ude0d"
    }
]

s = json.dumps(j) # convert to string (serialize j to a json formatted string)
j2 = json.loads(s) # deserialize s to a python object
df = json_normalize(j2) # load to a dataframe

             FieldA FieldB
0  regular string 1  ... 
1  regular string 2  ...