Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

take union of two dataframes pandas

m = {'left_only': 'df1', 'right_only': 'df2', 'both': 'df1, df2'}

result = df1.merge(df2, on=['A'], how='outer', indicator='B')
result['B'] = result['B'].map(m)

result
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #union #dataframes #pandas
ADD COMMENT
Topic
Name
4+2 =