[英]remove duplicates from dataframe
I have a dataframe "df" like the sample below. 我有一个数据框“ df”,如下面的示例。 I would like to use address and business_id as a unique key, and filter the dataframe so it only has unique records based on the combination of address and business_id.
我想使用address和business_id作为唯一键,并过滤数据框,使其仅具有基于address和business_id组合的唯一记录。 Can anyone suggest how to do that?
谁能建议该怎么做?
Code: 码:
print df[["address","business_id","city"]][1:3]
Sample Data: 样本数据:
address business_id city
1 2824 Milton Rd mLwM-h2YhXl2NCgdS84_Bw Charlotte
2 337 Danforth Avenue v2WhjAB3PIBA8J8VxG3wEg Toronto
除了删除重复项外,您还想使用df.set_index
df.set_index(keys=["address","business_id"])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.