我有兩個dataframes:如果在另一個數據框中存在相同的行,如何刪除Pandas數據框中的行?
df1 = row1;row2;row3
df2 = row4;row5;row6;row2
我希望我的輸出數據幀只包含在DF1獨特的行,即:
df_out = row1;row3
我如何獲得這個最有效的?
此代碼我想要做什麼,但使用2 for循環:
a = pd.DataFrame({0:[1,2,3],1:[10,20,30]})
b = pd.DataFrame({0:[0,1,2,3],1:[0,1,20,3]})
match_ident = []
for i in range(0,len(a)):
found=False
for j in range(0,len(b)):
if a[0][i]==b[0][j]:
if a[1][i]==b[1][j]:
found=True
match_ident.append(not(found))
a = a[match_ident]
沒有重複,因爲我沒有映射到兩個數據框中的公共值的唯一標識。 – RRC
不能標記它,但https://stackoverflow.com/questions/28901683/pandas-get-rows-which-are-not-in-other-dataframe – victor