提问人:dailyglen 提问时间:5/27/2012 最后编辑:piRSquareddailyglen 更新时间:1/5/2017 访问量:1197
使用索引 + 行匹配从数据帧中删除重复项
Removing duplicates from dataframe with index + row matching
问:
我有两个 s,我想将它们连接在一起,以便我删除了重复项的外部连接。我的问题是在查找重复项时忽略索引。如果索引不同,则不应重复。如果行索引和列是重复的,如何删除重复项?我唯一能想到的就是使用然后创建一个新的 DataFrame(效率非常低)。pandas
DataFrame
.drop_duplicates()
df.to_dict()
更新:
根据要求,这是我的数据示例:
from pandas import *
index1 = ['2012-05-2' + str(i) for i in range(0,6)]
data1 = {'rate': range(0,6)}
a = DataFrame(data1, index1)
index2 = ['2012-05-2' + str(i) for i in range(3,9)]
data2 = {'rate': range(3,9)}
b = DataFrame(data2, index2)
幽谷
答:
1赞
dailyglen
5/29/2012
#1
溶液:
a.combine_first(b)
谢谢韦斯。
评论
a.combine_first(b)
pandas.merge(A, B, method="outer")