用法:
Series.drop_duplicates(keep='first', inplace=False)
返回刪除重複值的係列。
- keep:
{‘first’, ‘last’,
False
},默認 ‘first’ 處理刪除重複項的方法:
‘first’:刪除除第一次出現的重複項。
‘last’:刪除除最後一次之外的重複項。
False
:刪除所有重複項。
- inplace:
布爾值,默認
False
如果
True
,就地執行操作並返回 None。
- keep:
- 係列或無
如果
inplace=True
,則刪除重複的係列或 None 。
參數:
返回:
例子:
生成具有重複條目的係列。
>>> s = pd.Series(['lama', 'cow', 'lama', 'beetle', 'lama', 'hippo'], ... name='animal') >>> s 0 lama 1 cow 2 lama 3 beetle 4 lama 5 hippo Name:animal, dtype:object
使用‘keep’ 參數,可以更改重複值的選擇行為。值 ‘first’ 保留每組重複條目的第一次出現。保持的默認值為‘first’。
>>> s.drop_duplicates() 0 lama 1 cow 3 beetle 5 hippo Name:animal, dtype:object
參數‘keep’ 的值‘last’ 保留每組重複條目的最後一次出現。
>>> s.drop_duplicates(keep='last') 1 cow 3 beetle 4 lama 5 hippo Name:animal, dtype:object
參數‘keep’ 的值
False
丟棄所有重複條目集。將 ‘inplace’ 的值設置為True
會就地執行操作並返回None
。>>> s.drop_duplicates(keep=False, inplace=True) >>> s 1 cow 3 beetle 5 hippo Name:animal, dtype:object
相關用法
- Python pandas.Series.drop用法及代碼示例
- Python pandas.Series.dropna用法及代碼示例
- Python pandas.Series.droplevel用法及代碼示例
- Python pandas.Series.dt.day_name用法及代碼示例
- Python pandas.Series.dt.is_year_end用法及代碼示例
- Python pandas.Series.divide用法及代碼示例
- Python pandas.Series.dt.weekday用法及代碼示例
- Python pandas.Series.div用法及代碼示例
- Python pandas.Series.dt.to_pydatetime用法及代碼示例
- Python pandas.Series.dt.second用法及代碼示例
- Python pandas.Series.dt.tz_localize用法及代碼示例
- Python pandas.Series.dt.is_leap_year用法及代碼示例
- Python pandas.Series.divmod用法及代碼示例
- Python pandas.Series.dt.is_quarter_start用法及代碼示例
- Python pandas.Series.dot用法及代碼示例
- Python pandas.Series.dt.tz_convert用法及代碼示例
- Python pandas.Series.dt.round用法及代碼示例
- Python pandas.Series.dt.nanosecond用法及代碼示例
- Python pandas.Series.dt.to_period用法及代碼示例
- Python pandas.Series.dt.ceil用法及代碼示例
注:本文由純淨天空篩選整理自pandas.pydata.org大神的英文原創作品 pandas.Series.drop_duplicates。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。