- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 19.2k
 
DOC: Fixed the doctsring for _set_axis_name (GH 22895) #22969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 13 commits
a5fd1c3
              5dbbbd1
              bc865d4
              457c58e
              e469e4e
              7fb8a52
              067fa8d
              71f3909
              a7eb3d8
              96a5dd1
              22ef507
              b030a6b
              6d76d44
              adc2694
              9d944e8
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -1118,7 +1118,7 @@ def f(x): | |
| 
     | 
||
| def rename_axis(self, mapper, axis=0, copy=True, inplace=False): | ||
| """ | ||
| Alter the name of the index or columns. | ||
| Set the name of the index or columns. | ||
| 
     | 
||
| Parameters | ||
| ---------- | ||
| 
          
            
          
           | 
    @@ -1154,29 +1154,40 @@ def rename_axis(self, mapper, axis=0, copy=True, inplace=False): | |
| -------- | ||
| **Series** | ||
| 
     | 
||
| >>> s = pd.Series([1, 2, 3]) | ||
| >>> s.rename_axis("foo") | ||
| foo | ||
| 0 1 | ||
| 1 2 | ||
| 2 3 | ||
| dtype: int64 | ||
| >>> s = pd.Series(["dog", "cat", "monkey"]) | ||
| >>> s | ||
| 0 dog | ||
| 1 cat | ||
| 2 monkey | ||
| dtype: object | ||
| >>> s.rename_axis("animal") | ||
| animal | ||
| 0 dog | ||
| 1 cat | ||
| 2 monkey | ||
| dtype: object | ||
| 
     | 
||
| **DataFrame** | ||
| 
     | 
||
| >>> df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}) | ||
| >>> df.rename_axis("foo") | ||
| A B | ||
| foo | ||
| 0 1 4 | ||
| 1 2 5 | ||
| 2 3 6 | ||
| 
     | 
||
| >>> df.rename_axis("bar", axis="columns") | ||
| bar A B | ||
| 0 1 4 | ||
| 1 2 5 | ||
| 2 3 6 | ||
| >>> df = pd.DataFrame({"num_legs": [4, 4, 2], | ||
| ... "num_arms": [0, 0, 2]}, | ||
| ... ["dog", "cat", "monkey"]) | ||
                
       | 
||
| >>> df | ||
| num_legs num_arms | ||
| dog 4 0 | ||
| cat 4 0 | ||
| monkey 2 2 | ||
| >>> df.rename_axis("animal") | ||
| num_legs num_arms | ||
| animal | ||
| dog 4 0 | ||
| cat 4 0 | ||
| monkey 2 2 | ||
| >>> df.rename_axis("limbs", axis="columns") | ||
| limbs num_legs num_arms | ||
| dog 4 0 | ||
| cat 4 0 | ||
| monkey 2 2 | ||
| """ | ||
| inplace = validate_bool_kwarg(inplace, 'inplace') | ||
| non_mapper = is_scalar(mapper) or (is_list_like(mapper) and not | ||
| 
        
          
        
         | 
    @@ -1194,45 +1205,58 @@ def rename_axis(self, mapper, axis=0, copy=True, inplace=False): | |
| 
     | 
||
| def _set_axis_name(self, name, axis=0, inplace=False): | ||
| """ | ||
| Alter the name or names of the axis. | ||
| Set the name(s) of the axis. | ||
| 
     | 
||
| Parameters | ||
| ---------- | ||
| name : str or list of str | ||
| Name for the Index, or list of names for the MultiIndex | ||
| axis : int or str | ||
| 0 or 'index' for the index; 1 or 'columns' for the columns | ||
| inplace : bool | ||
| whether to modify `self` directly or return a copy | ||
| Name(s) to set. | ||
| axis : {0 or 'index', 1 or 'columns'}, default 0 | ||
| The axis to set the label. The value 0 or 'index' specifies index, | ||
                
      
                  datapythonista marked this conversation as resolved.
               
          
            Show resolved
            Hide resolved
         | 
||
| and the value 1 or 'columns' specifies columns. | ||
| inplace : boolean, default False | ||
| If `True`, do operation inplace and return None. | ||
| 
     | 
||
| .. versionadded:: 0.21.0 | ||
| 
     | 
||
| Returns | ||
| ------- | ||
| renamed : same type as caller or None if inplace=True | ||
| Series, DataFrame, or None | ||
| The same type as the caller or `None` if `inplace` is `True`. | ||
| 
     | 
||
| See Also | ||
| -------- | ||
| pandas.DataFrame.rename | ||
| pandas.Series.rename | ||
| pandas.Index.rename | ||
| pandas.DataFrame.rename : Alter the axis labels of :class:`DataFrame`. | ||
| pandas.Series.rename : Alter the index labels or set the index name | ||
| of :class:`Series`. | ||
| pandas.Index.rename : Set the name of :class:`Index` | ||
| or :class:`MultiIndex`. | ||
| 
     | 
||
| Examples | ||
| -------- | ||
| >>> df._set_axis_name("foo") | ||
| A | ||
| foo | ||
| 0 1 | ||
| 1 2 | ||
| 2 3 | ||
| >>> df.index = pd.MultiIndex.from_product([['A'], ['a', 'b', 'c']]) | ||
| >>> df._set_axis_name(["bar", "baz"]) | ||
| A | ||
| bar baz | ||
| A a 1 | ||
| b 2 | ||
| c 3 | ||
| """ | ||
| >>> df = pd.DataFrame({"num_legs": [4, 4, 2]}, | ||
| ... ["dog", "cat", "monkey"]) | ||
| >>> df | ||
| num_legs | ||
| dog 4 | ||
| cat 4 | ||
| monkey 2 | ||
| >>> df._set_axis_name("animal") | ||
| num_legs | ||
| animal | ||
| dog 4 | ||
| cat 4 | ||
| monkey 2 | ||
| >>> df.index = pd.MultiIndex.from_product( | ||
| ... [["mammal"], ['dog', 'cat', 'monkey']]) | ||
| >>> df._set_axis_name(["type", "name"]) | ||
| legs | ||
| type name | ||
| mammal dog 4 | ||
| cat 4 | ||
| monkey 2 | ||
| """ | ||
| pd.MultiIndex.from_product([["mammal"], ['dog', 'cat', 'monkey']]) | ||
| axis = self._get_axis_number(axis) | ||
| idx = self._get_axis(axis).set_names(name) | ||
| 
     | 
||
| 
          
            
          
           | 
    ||
Uh oh!
There was an error while loading. Please reload this page.