Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append multiple pandas data frames at once

I am trying to find some way of appending multiple pandas data frames at once rather than appending them one by one using

df.append(df) 

Let us say there are 5 pandas data frames t1, t2, t3, t4, t5. How do I append them at once? Something equivalent of

df = rbind(t1,t2,t3,t4,t5) 
like image 355
user3664020 Avatar asked Apr 10 '16 05:04

user3664020


People also ask

Can we append multiple DataFrames in pandas?

pandas. DataFrame. append() method is used to append one DataFrame row(s) and column(s) with another, it can also be used to append multiple (three or more) DataFrames.


2 Answers

I think you can use concat:

print pd.concat([t1, t2, t3, t4, t5]) 

Maybe you can ignore_index:

print pd.concat([t1, t2, t3, t4, t5], ignore_index=True) 

More info in docs.

like image 188
jezrael Avatar answered Oct 13 '22 04:10

jezrael


Have you simply tried using a list as argument of append? Or am I missing anything?

import numpy as np import pandas as pd  dates = np.asarray(pd.date_range('1/1/2000', periods=8)) df1 = pd.DataFrame(np.random.randn(8, 4), index=dates, columns=['A', 'B', 'C', 'D']) df2 = df1.copy() df3 = df1.copy() df = df1.append([df2, df3])  print df 
like image 45
tfv Avatar answered Oct 13 '22 05:10

tfv