码迷,mamicode.com
首页 > 其他好文 > 详细

pandas.Series.duplicated

时间:2019-11-22 23:42:46      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:view   can   imp   occurred   ima   style   ica   none   enc   

Series.duplicated(selfkeep=‘first‘)

Indicate duplicate Series values.

Duplicated values are indicated as True values in the resulting Series. Either all duplicates, all except the first or all except the last occurrence of duplicates can be indicated.

Parameters:
keep {‘first’, ‘last’, False}, default ‘first’
  • ‘first’ : Mark duplicates as True except for the first occurrence.
  • ‘last’ : Mark duplicates as True except for the last occurrence.
  • False : Mark all duplicates as True.
Returns:
Series

Series indicating whether each value has occurred in the preceding values.

 

Examples:

By default, for each set of duplicated values, the first occurrence is set on False and all others on True:

>>> animals = pd.Series([‘lama‘, ‘cow‘, ‘lama‘, ‘beetle‘, ‘lama‘])
>>> animals.duplicated()
0    False
1    False
2     True
3    False
4     True
dtype: bool

which is equivalent to

 

>>> animals.duplicated(keep=‘first‘)
0    False
1    False
2     True
3    False
4     True
dtype: bool

  

 By using ‘last’, the last occurrence of each set of duplicated values is set on False and all others on True:
>>> animals.duplicated(keep=‘last‘)
0     True
1    False
2     True
3    False
4    False
dtype: bool

 

By setting keep on False, all duplicates are True:

 

 
>>> animals.duplicated(keep=False)
0     True
1    False
2     True
3    False
4     True
dtype: bool

  

 

  

pandas.Series.duplicated

标签:view   can   imp   occurred   ima   style   ica   none   enc   

原文地址:https://www.cnblogs.com/zjuhaohaoxuexi/p/11914671.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!