Skip to content

Instantly share code, notes, and snippets.

@blacksmithop
Last active August 3, 2022 09:08
Show Gist options
  • Save blacksmithop/72795926c01cb63d3edad824591ce134 to your computer and use it in GitHub Desktop.
Save blacksmithop/72795926c01cb63d3edad824591ce134 to your computer and use it in GitHub Desktop.
Drop duplicate row if column is null
>>> df1
name flag
0 1 1
1 2 1
2 3 1
3 4 1
>>> df2
name flag
0 3 NaN
1 4 NaN
>>>
>>> df = df1.append(df2)
<stdin>:1: FutureWarning: The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead.
>>>
>>> df
name flag
0 1 1.0
1 2 1.0
2 3 1.0
3 4 1.0
0 3 NaN
1 4 NaN
>>>
>>>
>>> _flags = df.flag.notna()
>>>
>>> _names = ~df.name.duplicated()
>>>
>>> df[_flags & _names]
name flag
0 1 1.0
1 2 1.0
2 3 1.0
3 4 1.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment