0

have two df.both df's with one column and same names

df1 have 40000 rows and df 2 have 80000 rows.

How to compare whether the data in df1 is same as of df2.

Expected output : any message stating that 40000 rows in df1 matched with df2 which has 80000 rows

40000 items in df1 matched with 80000 items in df2 


  • Please take the time to read this post on [how to provide a great pandas example](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) as well as how to provide a [minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) and revise your question accordingly. These tips on how to ask a good question may also be useful. – yatu May 16 '19 at 11:45
  • sure will do that –  May 16 '19 at 11:48
  • @hukkemaaru You need Matched Columns or just the message – Prathik Kini May 16 '19 at 11:53
  • if possible both else matched columns will do the job. –  May 16 '19 at 11:54

4 Answers4

0

Something like:

m = df1['c'] == df2['c']
print('{0:d} items in df1 matched with {1:d} items in df2'.format(sum(m), len(m)))
prosti
  • 42,291
  • 14
  • 186
  • 151
0

Use this:

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


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

Try:

 matches = (df2 == df1).stack()
desertnaut
  • 57,590
  • 26
  • 140
  • 166
0
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

Matched element

Prathik Kini
  • 1,067
  • 11
  • 25