[Python] save a list of different Dataframes to json

Discussão em 'Python' iniciado por Stack, Dezembro 21, 2024.

  1. Stack

    Stack Membro Participativo

    I have different pandas dataframes, which I put in a list. I want to save this list in json (or any other format) which can be read by R.

    import pandas as pd

    def create_df_predictions(extra_periods):
    """
    make a empty df for predictions
    params: extra_periods = how many prediction in the future the user wants
    """
    df = pd.DataFrame({ 'model': ['a'], 'name_id': ['a'] })
    for col in range(1, extra_periods+1):
    name_col = 'forecast' + str(col)
    df[name_col] = 0

    return df

    df1 = create_df_predictions(9)
    df2 = create_df_predictions(12)
    list_df = [df1, df2]


    The question is how to save list_df in a readable format for R? Note that df1 and df2 are have a different amount of columns!

    Continue reading...

Compartilhe esta Página