4

I would like to have in python the same behavior as the MATLAB function outerjoin.

I've been using pandas.merge, but the result is different in case of having NaNs.

matlab

t1 = table([24;25], [NaN;10], 'VariableNames',{'a50','a36'});
t2 = table([NaN;10], 'VariableNames',{'a36'});
t = outerjoin(t1,t2,'MergeKeys',true,'Type','Right')

a50    a36
___    ___
 25     10
NaN    NaN

python

import numpy as np
import pandas as pd
t1 = pd.DataFrame({'a50': [24,25], 'a36': [np.nan, 10]})
t2 = pd.DataFrame({'a36': [np.nan, 10]})
t = pd.merge(t1, t2, how='right')

a50    a36
___    ___
 24    NaN
 25   10.0

Any other alternative? Thanks

P. Ma
  • 51
  • 4
  • [This question](https://stackoverflow.com/q/23940181/4221706) is very closely related, as it discusses the unexpected behavior of `pandas.merge` with NaNs. – hbaderts Jun 05 '18 at 11:26

0 Answers0