Last active
August 3, 2022 09:08
-
-
Save blacksmithop/72795926c01cb63d3edad824591ce134 to your computer and use it in GitHub Desktop.
Drop duplicate row if column is null
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> 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