In [1]:
import pandas as pd
import numpy as np
In [4]:
df1=pd.DataFrame(np.array([1,2,3]))
df1.columns=['Var1']
df1
Out[4]:
Var1 | |
---|---|
0 | 1 |
1 | 2 |
2 | 3 |
In [9]:
df2=pd.DataFrame(np.array([4,5,6]))
df2.columns=['Var1']
df2
Out[9]:
Var1 | |
---|---|
0 | 4 |
1 | 5 |
2 | 6 |
In [7]:
df3=[]
df3
Out[7]:
[]
Storing df1,df2 and df3 in a list¶
In [10]:
l1=[df1,df2,df3]
l1
Out[10]:
[ Var1 0 1 1 2 2 3, Var1 0 4 1 5 2 6, []]
We need to row wise bind the elements in the list¶
Since there is an empty list present in l1, we cant use pd.concat function directly on l1.We need to create another list with only df1 and df2 stored within the new list¶
In [19]:
l2=[]
for i in l1:
if len(i)==0:
temp=1
else:
l2.append(i)
l2
Out[19]:
[ Var1 0 1 1 2 2 3, Var1 0 4 1 5 2 6]
Concatenating l2¶
In [20]:
final_df=pd.concat(l2)
final_df
Out[20]:
Var1 | |
---|---|
0 | 1 |
1 | 2 |
2 | 3 |
0 | 4 |
1 | 5 |
2 | 6 |