I have a boolean series that I got from using .duplicated. I'm trying to figure out what rows of my dataframe are returning True (and what the data is in those rows). How can I use this boolean series to extract those rows?
Thanks - KC
EDIT- Data sample:
level_0 index ID date_time value
54967 54967 54967 1/06/2016 19:30 1.00
54968 54968 54968 1/06/2016 19:30 2.00
54969 54969 54969 1/06/2016 19:43 3.00
54970 54970 54970 1/06/2016 19:46 4.00
Want to return this:
level_0 index ID date_time value
54967 54967 54967 1/06/2016 19:30 1.00
54968 54968 54968 1/06/2016 19:30 2.00
use keep=False
parameter when calling .duplicated()
df[df.duplicated(subset='date_time', keep=False)]
Test:
In [53]: df
Out[53]:
evel_0 index ID date_time value
0 54967 54967 54967 2016-01-06 19:30:00 1.0
1 54968 54968 54968 2016-01-06 19:30:00 2.0
2 54969 54969 54969 2016-01-06 19:43:00 3.0
3 54968 54968 54968 2016-01-06 19:30:00 5.0
4 54970 54970 54970 2016-01-06 19:46:00 4.0
In [54]: df[df.duplicated(subset='date_time', keep=False)]
Out[54]:
evel_0 index ID date_time value
0 54967 54967 54967 2016-01-06 19:30:00 1.0
1 54968 54968 54968 2016-01-06 19:30:00 2.0
3 54968 54968 54968 2016-01-06 19:30:00 5.0
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.