DataFrame.drop_duplicates(*args, **kwargs) Return DataFrame with
duplicate rows removed, optionally only considering certain columns
Parameters: subset : column label or sequence of labels, optional
Only consider certain columns for identifying duplicates, by default
use all of the columns keep : {‘first’, ‘last’, False}, default
‘first’ first : Drop duplicates except for the first occurrence. last
: Drop duplicates except for the last occurrence. False : Drop all
duplicates. take_last : deprecated inplace : boolean, default False
Whether to drop duplicates in place or to return a copy cols : kwargs
only argument of subset [deprecated] Returns: deduplicated :
DataFrame
现在在pandas中使用drop_duplicates和keep参数就容易多了。
如果要将结果存储在另一个数据集中:
或者
如果需要更新同一数据集:
上面的示例将删除所有重复项并保留一个,类似于SQL中的
DISTINCT *
只想在本关于drop_duplicates的回答中加上:
keep
:{'first','last',False},默认'first'第一次:删除除第一次出现以外的重复项。
last:除去最后一次出现的重复项。
错误:删除所有重复项。
因此,将
keep
设置为False,我们将为您提供所需的答案。相关问题 更多 >
编程相关推荐