@@ -1469,7 +1469,7 @@ def __xor__(self, other):
1469
1469
1470
1470
def union (self , other ):
1471
1471
"""
1472
- Form the union of two Index objects and sorts if possible
1472
+ Form the union of two Index objects and sorts if possible.
1473
1473
1474
1474
Parameters
1475
1475
----------
@@ -1478,6 +1478,15 @@ def union(self, other):
1478
1478
Returns
1479
1479
-------
1480
1480
union : Index
1481
+
1482
+ Examples
1483
+ --------
1484
+
1485
+ >>> idx1 = pd.Index([1, 2, 3, 4])
1486
+ >>> idx2 = pd.Index([3, 4, 5, 6])
1487
+ >>> idx1.union(idx2)
1488
+ Int64Index([1, 2, 3, 4, 5, 6], dtype='int64')
1489
+
1481
1490
"""
1482
1491
self ._assert_can_do_setop (other )
1483
1492
other = _ensure_index (other )
@@ -1545,8 +1554,10 @@ def _wrap_union_result(self, other, result):
1545
1554
1546
1555
def intersection (self , other ):
1547
1556
"""
1548
- Form the intersection of two Index objects. Sortedness of the result is
1549
- not guaranteed
1557
+ Form the intersection of two Index objects.
1558
+
1559
+ This returns a new Index with elements common to the index and `other`.
1560
+ Sortedness of the result is not guaranteed.
1550
1561
1551
1562
Parameters
1552
1563
----------
@@ -1555,6 +1566,15 @@ def intersection(self, other):
1555
1566
Returns
1556
1567
-------
1557
1568
intersection : Index
1569
+
1570
+ Examples
1571
+ --------
1572
+
1573
+ >>> idx1 = pd.Index([1, 2, 3, 4])
1574
+ >>> idx2 = pd.Index([3, 4, 5, 6])
1575
+ >>> idx1.intersection(idx2)
1576
+ Int64Index([3, 4], dtype='int64')
1577
+
1558
1578
"""
1559
1579
self ._assert_can_do_setop (other )
1560
1580
other = _ensure_index (other )
@@ -1589,21 +1609,26 @@ def intersection(self, other):
1589
1609
1590
1610
def difference (self , other ):
1591
1611
"""
1592
- Compute sorted set difference of two Index objects
1612
+ Return a new Index with elements from the index that are not in `other`.
1613
+
1614
+ This is the sorted set difference of two Index objects.
1593
1615
1594
1616
Parameters
1595
1617
----------
1596
1618
other : Index or array-like
1597
1619
1598
1620
Returns
1599
1621
-------
1600
- diff : Index
1622
+ difference : Index
1601
1623
1602
- Notes
1603
- -----
1604
- One can do either of these and achieve the same result
1624
+ Examples
1625
+ --------
1626
+
1627
+ >>> idx1 = pd.Index([1, 2, 3, 4])
1628
+ >>> idx2 = pd.Index([3, 4, 5, 6])
1629
+ >>> idx1.difference(idx2)
1630
+ Int64Index([1, 2], dtype='int64')
1605
1631
1606
- >>> index.difference(index2)
1607
1632
"""
1608
1633
self ._assert_can_do_setop (other )
1609
1634
@@ -1623,7 +1648,6 @@ def sym_diff(self, other, result_name=None):
1623
1648
1624
1649
Parameters
1625
1650
----------
1626
-
1627
1651
other : Index or array-like
1628
1652
result_name : str
1629
1653
0 commit comments