[Python] Import json file in python and use pandas to create a dataframe Discussion

Discussão em 'Python' iniciado por Stack, Fevereiro 11, 2025.

  1. Stack

    Stack Membro Participativo

    I have imported a JSON file in Python for extrapolate the information that I have in it for selecting every single data or principal data that contains different data, but when I try to select the principal data to see all the data that contains I can't see the data, but see only the first data of the principal paragraph,how it is possible ? Or I can't see the data transformed in a table

    For example I have this index with this data but I can't see all the data that this index contains when I recall AccessLevels from JSON with code like this:

    Accesso = df['AccessLevels']
    print(Accesso)


    "AccessLevels": {
    "Home.btnBuzzer": 0,
    "Home.btnLogin": 0,
    "Home.btnLogout": 0,
    "Home.btnMenu": 0,
    "L2A_ConfEdit.btnRecSave": 2,
    "L2A_ConfEdit.cbNameConf": 4,
    "L2A_ConfEdit.editParameters": 4,
    "L2B_ProgEdit.btnRecActivate": 1,
    "L2B_ProgEdit.btnRecSave": 2,
    "L2B_ProgEdit.btnRecSaveAs": 2,
    "L2B_ProgEdit.cbNameProg": 1,
    "L2B_ProgEdit.editParameters": 2,
    "L2E_Stats.btnRstPar": 1,
    "L2E_Stats.btnRstTot": 2,
    "L2_Menu.btnConfEdit": 0,
    "L2_Menu.btnMaint": 4,
    "L2_Menu.btnProgEdit": 0,
    "L2_Menu.btnRtCmds": 0,
    "L2_Menu.btnStats": 0,
    "L2_Menu.btnTestControl": 2
    },


    The result of printing the access level is this:

    Home.btnBuzzer 0.0
    Home.btnLogin 0.0
    Home.btnLogout 0.0
    Home.btnMenu 0.0
    L2A_ConfEdit.btnRecSave 2.0
    ...
    5 NaN
    6 NaN
    7 NaN
    8 NaN
    9 NaN
    Name: AccessLevels, Length: 74, dtype: float64


    The JSON file is containing about 12k lines

    import json
    import pandas as pd

    # Replace 'your_file.json' with the path to your JSON file
    with open('00_000000065.json', 'r') as file:
    data = json.load(file)

    #stampo il file json intero
    #print(data)


    df = pd.DataFrame(data)
    #Info = df['Info']['CPU12 prog code']
    #print(Info)
    #print("\nstampo tutto il file json come database per vedere come funziona")
    #print(df)

    print("\nStampo le ricette\n")
    #Ricetta = df['Recipes']
    #Step = df['Recipes']['Programs']['13']['Step']['007']
    #print(f"Stampami step {Step}")

    Info = df['Info']['CPU12 prog code']
    print(Info)

    Image = df['zImages']['0']
    print(Image)


    Step1 = df['Recipes']['Configs']['00']['Step']

    print(Step1)

    print("\ntest dei vari livelli\n")
    Accesso = df['AccessLevels']
    print(Accesso)

    print("\nStampo il contatore\n")
    Contatore = df['CounterEnabled']
    print(Contatore)

    Continue reading...

Compartilhe esta Página