1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Need to convert CSV to nested Json, In nested json pivot the values [closed]

Discussão em 'Python' iniciado por Stack, Setembro 15, 2024.

  1. Stack

    Stack Membro Participativo

    #Output should give in the json format.

    please look into the source data, license field values are transformed into keys and nested loops are used. I have tried the logic and failed with the nested loop transformation.

    { "CNR": 10, "dept": "test1", "license": { "LOI": { "": { "state": [ { "": [] "AP": ["KDP","CHTR","KNL"] "TS": ["HYD","WNGL","KMNR"]}
    ]
    }
    },
    "TLCO": {
    "*": {
    "*": []
    }
    },
    "PREM": {
    "CondensedMktShare": {
    "state": [
    {
    "*": []
    }
    ]
    },
    "REM": {
    "*": []
    }
    }
    }
    }


    #Source CSV

    CNR dept license report state county
    10 test1 LOI \* \* \*
    10 test1 TLCO \* \* \*
    10 test1 LOI \* AP KDP
    10 test1 PREM CondensedMktShare \* \*
    10 test1 REM \*
    10 test1 LOI \* AZ MARI
    10 test1 LOI \* AP CHTR
    10 test1 LOI \* AP KNL
    10 test1 LOI \* TS HYD
    10 test1 LOI \* TS WNGL
    10 test1 LOI \* TS KMNR


    expecting any code or reference links. thanks in advance for your time.

    Continue reading...

Compartilhe esta Página