[Python] python basics: can someone help me understand processing one file vs processing all...

Discussão em 'Python' iniciado por Stack, Agosto 25, 2025.

  1. Stack

    Stack Membro Participativo

    This will output all csv files from the directory, but only show one of the csv dataframes.

    OUTPUT_PATH = "./static/output/"
    FILE_LIST = glob.glob("./static/*.json")
    def all_data():
    for fname in FILE_LIST:
    i = open(fname, "r")
    lst = []
    lst.append(fname)
    file_data = json.loads(i.read())
    data = {"annual": {}}
    ....processing stuff here.....
    df = pd.DataFrame(data)
    df.to_csv(OUTPUT_PATH + fname.split("/" [-1].replace(".json",".csv"))
    return df
    all_data()
    print(all_data())


    This will print all the dataframes:

    for fname in FILE_LIST:
    i = open(fname, "r")
    lst = []
    lst.append(fname)
    file_data = json.loads(i.read())
    data = {"annual": {}}
    ....processing stuff here.....
    df = pd.DataFrame(data)
    print(df)


    how can i use the first example to show me all the dataframes for me to further work on? I also tried concat them together, but it still just prints one dataframe.

    Continue reading...

Compartilhe esta Página