Reputation: 13806
I have two data frame df1
, df2
, which I want to combine to the new dataframe df
. This however creates an row with all NaN:
>>> from pandas import DataFrame
>>> df1 = DataFrame({'col1':[1,2,3], 'col2':[2,3,4]})
>>> df2 = DataFrame({'col1':[4,2,5], 'col2':[6,3,5]})
>>> df = df2[~df2.isin(df1)]
>>> df
col1 col2
0 4 6
1 NaN NaN
2 5 5
How can I remove this row, such that df
looks like:
>>> df
col1 col2
0 4 6
2 5 5
Upvotes: 13
Views: 23510
Reputation: 879143
You could use dropna:
In [13]: df2[df1 != df2].dropna(how='all')
Out[13]:
col1 col2
0 4 6
2 5 5
Upvotes: 23
Reputation: 13806
>>> df = df2[~df2.isin(df1).all(1)]
>>> df
col1 col2
0 4 6
2 5 5
Upvotes: 2