Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to combine (merge) an array of identical DataFrames into a single one?

How do I merge or combine an array of DataFrames in pandas?

dfs = []
for df in pd.read_csv(....chunksize=chunk_size):
  df1 = df
  # ....
  if condition:
    dfs.append(df1)

As you can see, they all have the same structure, I just need to combine them in a single DataFrame.


1 Answers

normally you can concatenate your array of data frame so you could have

import pandas as pd

dfs = []
for df in pd.read_csv(....chunksize=chunk_size):
  df1 = df
  # ....
  if condition:
    dfs.append(df1)
result = pd.concat(dfs)

you can find more info on this , here.

like image 100
user 12321 Avatar answered Dec 06 '25 06:12

user 12321



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!