0

I am trying to merge two dataframes:

this are tables I am trying to merge

and this is the result I want to achieve

So, I want merged values not to be on the same row.

When I try to merge like that:

pd.merge(a,b,how='inner', on=['date_install','device_os'])

it merges values in one raw.

Please,suggest how it can be resolved

Liz Hi
  • 3
  • 1
  • 5

2 Answers2

0

You can use append():

df1.append(df2, ignore_index = True)

or by using concat():

pd.concat([df,df1], ignore_index = True)

or using merge():

df.merge(df1, how = 'outer')
Loochie
  • 2,414
  • 13
  • 20
0

Reference taken from: https://stackoverflow.com/a/24391268/3748167 (probable duplicate)

The only difference here is concatenating both dataframes first and then applying rest of the logic.

def sjoin(x): return ';'.join(x[x.notnull()].astype(str)) pd.concat([a,b]).groupby(level=0, axis=1).apply(lambda x: x.apply(sjoin, axis=1))

Mudra
  • 36
  • 8