phoenix
phoenix

Reputation: 338

Concatenate non empty dataframes

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

Upvotes: 1

Views: 2345

Answers (1)

YOLO
YOLO

Reputation: 21719

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])

Upvotes: 5

Related Questions