-1

i have a dataframe df1

 id  Name  City   type 
 1   Anna  Paris   AB
 2   Marc   Rome   D
 3   erika  madrid AC

and a dataframe df2

 id  Name  City   type 
 1   Anna  Paris   B

and a dataframe df3

 id  Name  City   type 
 1   Anna  Paris   C

i want to append df2 and df3 to df1 , this is my expected output :

 id  Name  City   type 
 1   Anna  Paris   AB
 2   Marc   Rome   D
 3   erika  madrid AC
 1   Anna  Paris   B
 1   Anna  Paris   C

df1  = df1.append(df2)
df1  = df1.append(df3)

but the dataframe add only the last row and delete the other rows with the same id

 id  Name  City   type 
 2   Marc   Rome   D
 3   erika  madrid AC
 1   Anna  Paris   C  

i mtrying also concat

df1= pd.concat([df1,df2,df3], join='inner')
khaoula
  • 67
  • 1
  • 8

1 Answers1

0

I think the problem with pd.concat() is that you are passing the parameter join = inner. I expect this to work:

output = pd.concat([df1,df2,df3])

Using this an example code:

df1 = pd.DataFrame({'Name':['Anna','Marc','erika'],
                    'City':['Paris','Rome','madrid'],
                    'Type':['AB','D','AC']})
df2 = pd.DataFrame({'Name':['Anna'],
                    'City':['Paris'],
                    'Type':['B']})
df3 = pd.DataFrame({'Name':['Anna'],
                    'City':['Paris'],
                    'Type':['C']})
pd.concat([df1,df2,df3])

It outputs:

    Name    City Type
0   Anna   Paris   AB
1   Marc    Rome    D
2  erika  madrid   AC
0   Anna   Paris    B
0   Anna   Paris    C
Celius Stingher
  • 17,835
  • 6
  • 23
  • 53