Home > database >  How to combine the dataframes in "df1" one after another
How to combine the dataframes in "df1" one after another

Time:03-26

for ticker in tickers['ticker']:
    try:
        df_sql = df_sql_all[df_sql_all["ticker"] == ticker]
        revenue = int(df_sql['revenue'].values[0])
        opinc = int(df_sql['opinc'].values[0])
        netinc = int(df_sql['netinc'].values[0])
        gp = int(df_sql['gp'].values[0])
        df1 = df[df.value.isin([revenue, opinc, netinc, gp])]
        display(df1)
    except:
        continue

CodePudding user response:

You can use a list as a container for all df1 dataframes. At the end, concatenate them all.

data = []

for ticker in tickers['ticker']:
    try:
        ...
        df1 = df[df.value.isin([revenue, opinc, netinc, gp])]
        data.append(df1)
        ...
    except:
        continue

df1 = pd.concat(data)
  • Related