簡體   English   中英

如何將一個數據幀與另一個數據幀進行比較並檢查第二個 df 中是否存在第一個 df 中的相同數據

[英]How to compare one dataframe with another and check whether the same data in first df present in second df

有兩個 df.both df 的一列和相同的名稱

df1 有 40000 行,df 2 有 80000 行。

如何比較df1中的數據與df2中的數據是否相同。

預期輸出:任何說明 df1 中的 40000 行與 df2 匹配的消息,其中 df2 有 80000 行

40000 items in df1 matched with 80000 items in df2 


就像是:

m = df1['c'] == df2['c']
print('{0:d} items in df1 matched with {1:d} items in df2'.format(sum(m), len(m)))

用這個:

match = df1[df1['column name'].isin(df2['column name'])].shape[0]


print(('%.i items matched') % match)

嘗試:

 matches = (df2 == df1).stack()
df = pd.DataFrame(data1, columns = ['A'])
df2 = pd.DataFrame(data2, columns = ['A'])
df
    A
0  10
1  15
2  14
3  20
4  25
5  26

 df2
    A
0  10
1  15
2  14
3  20
4  25
5  26
6  30
7  32
8  34
9  36



df2[df2.A.isin(df.A.values)]
    A
0  10
1  15
2  14
3  20
4  25
5  26

匹配元素

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM