SHARE
TWEET

pandas - merge - join inner

furas Aug 3rd, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. data1 = '''#PARTNER_NAME   TOTAL_NO_OF_RECORDS TOTAL_QUANTITY
  2. a   22142   309941.01
  3. b   1719    34301.67
  4. d   4376    345460.7
  5. e   73723   2166729.41
  6. c   2045    165651
  7. f   307 1827993.54
  8. b   1719    34301.67
  9. c   2039    165674'''
  10.  
  11. data2 = '''Records Quantity
  12. 2045    165651
  13. 22142   309941.01
  14. 17  312
  15. 2   300
  16. 640 9375.75
  17. 68  256
  18. 1719    34301.67
  19. 2899    219700.8707
  20. 451 6658.06
  21. 70  3179.24
  22. 776 6849.52'''
  23.  
  24. import io
  25. import pandas as pd
  26.  
  27. f1 = io.StringIO(data1)
  28. f2 = io.StringIO(data2)
  29.  
  30. df1 = pd.read_csv(f1, sep="\s+")
  31. df2 = pd.read_csv(f2, sep="\s+")
  32.  
  33. #print(df1)
  34. #print(df1.columns)
  35.  
  36. #print(df2)
  37. #print(df2.columns)
  38.  
  39. #print('---')
  40.  
  41. print(pd.merge(df1, df2, left_on='TOTAL_NO_OF_RECORDS', right_on='Records',
  42.       how='inner', sort=False))
  43.  
  44. '''
  45.  #PARTNER_NAME  TOTAL_NO_OF_RECORDS  TOTAL_QUANTITY  Records   Quantity
  46. 0             a                22142       309941.01    22142  309941.01
  47. 1             b                 1719        34301.67     1719   34301.67
  48. 2             b                 1719        34301.67     1719   34301.67
  49. 3             c                 2045       165651.00     2045  165651.00
  50. '''
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top