• 把一个json文件写入到csv文件当中【多测师_王sir】


    把如下的example.json文件写进csv文件当中

    {
      "01": [
        {
          "picname": "01_sseye.png",
          "主观评分": "7",
          "主观评价": "ok"
        },
        {
          "picname": "01_ueeye.png",
          "主观评分": "8",
          "主观评价": "眼球"
        }
      ],
      "02": [
        {
          "picname": "02_sshair.png",
          "主观评分": "5",
          "主观评价": "ok"
        },
        {
          "picname": "02_uehair.png",
          "主观评分": "9",
          "主观评价": "ok"
        }
      ],
      "03": [
        {
          "picname": "03_ssll.png",
          "主观评分": "6",
          "主观评价": ""
        },
        {
          "picname": "03_uesll.png",
          "主观评分": "6",
          "主观评价": ""
        }
      ]
    }
    #coding=utf-8
    """
    ===========================
    Author:多测师_王sir
    Time:2020-09-17 11:53
    Wechat:xiaoshubass
    website:www.duoceshi.cn
    ===========================
    """
    
    import pandas as pd
    
    def read_example(path):
        data=pd.read_json(path)
        dict_data=data.to_dict()  #转换为字典
        list1=[]
        for i in dict_data.values():
            for j in i.values():
                list1.append(j)
        a=pd.DataFrame(list1)
        a.rename(columns={'picname':''},inplace=True)  #picname改为空
        #index = False 把第一列的索引值去掉
        csv=a.to_csv('C:projectdcs6decoratorexample.csv',encoding='utf-8',index=False)
        print(a)
    
    read_example('C:projectdcs6decoratorexample.json')
  • 相关阅读:
    ExtJS4.2学习(6)——基础知识之proxy篇
    undo损坏故障恢复(二)ORA-01092,ORA-00604,ORA-01110
    pat 1063. Set Similarity (25)
    汉语-汉字:彤
    地理-地名:九女集
    汉语-汉字:菅
    汉语-汉字:蒯
    汉语-汉字:旬
    汉语-汉字:弁
    汉语-汉字:尥
  • 原文地址:https://www.cnblogs.com/xiaoshubass/p/13686355.html
Copyright © 2020-2023  润新知