Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. In [1]: pin1= pd.Series(np.random.randn(2), index=['2', '4'])
  2. In [2]: pin2= pd.Series(np.random.randn(3), index=['0', '1', '7'])
  3. In [3]: pin3=pd.merge(pin1,pin2,how='outer')
  4. In [4]: pin3
  5. Out [4]:
  6. 0 0.2941
  7. 1 0.2869
  8. 2 1.7098
  9. 3 -0.2126
  10. 4 0.2696
  11.  
  12. Out [4]:
  13. 0 0.2941
  14. 1 0.2869
  15. 2 1.7098
  16. 4 -0.2126
  17. 7 0.2696
  18.  
  19. pd.concat([pin1, pin2]).sort_index()
  20.  
  21. In [3732]: pin1.combine_first(pin2)
  22. Out[3732]:
  23. 0 -0.820341
  24. 1 0.492719
  25. 2 -0.785723
  26. 4 -1.815021
  27. 7 2.027267
  28. dtype: float64
  29.  
  30. In [3734]: pin1.append(pin2).sort_index()
  31. Out[3734]:
  32. 0 -0.820341
  33. 1 0.492719
  34. 2 -0.785723
  35. 4 -1.815021
  36. 7 2.027267
  37. dtype: float64
  38.  
  39. In [3735]: pin1
  40. Out[3735]:
  41. 2 -0.785723
  42. 4 -1.815021
  43. dtype: float64
  44.  
  45. In [3736]: pin2
  46. Out[3736]:
  47. 0 -0.820341
  48. 1 0.492719
  49. 7 2.027267
  50. dtype: float64
  51.  
  52. pin1.align(pin2,join='outer')[0].fillna(pin1.align(pin2,join='outer')[1])
  53. Out[991]:
  54. 0 -0.278627
  55. 1 0.009388
  56. 2 -0.655377
  57. 4 0.564739
  58. 7 0.793576
  59. dtype: float64
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement