1
votes

I have n number of dataframes which is formed by downloading data from firestore. The number of dataframes depend on number of unique value of a variable. coming to the question, I want to concatenate these dataframes into one final dataframe. But I want to ignore the empty dataframes. How can I do this?

For example if I have df1,df2,df3,df4. if df3 is empty, I want to concatenate df1, df2 and df4

1
if df3 is empty without column names it will not get concatenated. else you can try pd.concat([i for i in list_of_dfs if len(i)!=0]) - anky

1 Answers

4
votes

I would do something like using .empty attribute:

def concat(*args):
    return pd.concat([x for x in args if not x.empty])

df = concat(*[df1, df2, df3, df4])