【问题标题】:Reading JSON Containing Emojis Into Pandas Dataframe将包含表情符号的 JSON 读入 Pandas 数据框
【发布时间】:2019-08-16 08:20:09
【问题描述】:

我收到 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")

但我无法阅读表情符号。有什么建议吗?

提前谢谢你。

【问题讨论】:

    标签: python pandas emoji


    【解决方案1】:

    您可以使用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  ... ?
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-11
      • 1970-01-01
      • 2017-09-25
      • 2020-08-27
      • 1970-01-01
      • 2020-11-06
      • 2021-10-09
      • 2019-07-25
      相关资源
      最近更新 更多