@@ -559,7 +559,7 @@ def set_axis(self, labels, axis=0, inplace=False):
559
559
"""
560
560
Assign desired index to given axis.
561
561
562
- Indexes for column or row labels can be changed by assigning
562
+ Indexes for%(extended_summary_sub)s row labels can be changed by assigning
563
563
a list-like or Index.
564
564
565
565
.. versionchanged:: 0.21.0
@@ -574,67 +574,23 @@ def set_axis(self, labels, axis=0, inplace=False):
574
574
labels : list-like, Index
575
575
The values for the new index.
576
576
577
- axis : {0 or 'index', 1 or 'columns'}, default 0
578
- The axis to update. The value 0 identifies the rows, and 1
579
- identifies the columns.
577
+ axis : %(axes_single_arg)s, default 0
578
+ The axis to update. The value 0 identifies the rows%(axis_description_sub)s.
580
579
581
580
inplace : bool, default False
582
581
Whether to return a new %(klass)s instance.
583
582
584
583
Returns
585
584
-------
586
585
renamed : %(klass)s or None
587
- An object of same type as caller if inplace=False, None otherwise.
586
+ An object of type %(klass)s if inplace=False, None otherwise.
588
587
589
588
See Also
590
589
--------
591
- DataFrame .rename_axis : Alter the name of the index or columns .
590
+ %(klass)s .rename_axis : Alter the name of the index%(see_also_sub)s .
592
591
593
592
Examples
594
593
--------
595
- **Series**
596
-
597
- >>> s = pd.Series([1, 2, 3])
598
- >>> s
599
- 0 1
600
- 1 2
601
- 2 3
602
- dtype: int64
603
-
604
- >>> s.set_axis(['a', 'b', 'c'], axis=0)
605
- a 1
606
- b 2
607
- c 3
608
- dtype: int64
609
-
610
- **DataFrame**
611
-
612
- >>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
613
-
614
- Change the row labels.
615
-
616
- >>> df.set_axis(['a', 'b', 'c'], axis='index')
617
- A B
618
- a 1 4
619
- b 2 5
620
- c 3 6
621
-
622
- Change the column labels.
623
-
624
- >>> df.set_axis(['I', 'II'], axis='columns')
625
- I II
626
- 0 1 4
627
- 1 2 5
628
- 2 3 6
629
-
630
- Now, update the labels inplace.
631
-
632
- >>> df.set_axis(['i', 'ii'], axis='columns', inplace=True)
633
- >>> df
634
- i ii
635
- 0 1 4
636
- 1 2 5
637
- 2 3 6
638
594
"""
639
595
if inplace :
640
596
setattr (self , self ._get_axis_name (axis ), labels )
0 commit comments