美文网首页
python在处理df中某列为str类型类似于json的,处理成

python在处理df中某列为str类型类似于json的,处理成

作者: 丙吉 | 来源:发表于2020-05-28 17:02 被阅读0次

    要处理的就是类似于 如下的数据框中的content列中的json串:

    对单个元素来说,可以直接这样生成数据框:
    json_normalize(json.loads(exp_json.iloc[0]['content'])['CAPS'])

    对整列生成数据框,代码如下:

    json_list = []

    for i in range(exp_json1.shape[0]):

        x = exp_json1.iloc[i]['content']

        if x is not None:

            tmp = json.loads(x)['CAPS']['CAPSApplicationDetails']['CapsOtherDetails']

            tmp = dict({'user_account_id':exp_json1.iloc[i]['user_account_id']}, **tmp)

    #        print(tmp)

            json_list.append(tmp)

    exp_json_df = pd.DataFrame(json_list)

    相关文章

      网友评论

          本文标题:python在处理df中某列为str类型类似于json的,处理成

          本文链接:https://www.haomeiwen.com/subject/nppaahtx.html