Change language

Python | Pandas dataframe.rename_axis ()

|

dataframe.rename_axis() is used to rename index axes or columns in a dataframe .

Syntax: DataFrame.rename_axis (mapper, axis = 0, copy = True, inplace = False)

Parameters:
mapper : [scalar, list-like, optional] Value to set the axis name attribute.
axis: int or string, default 0
copy: [iboolean, default True] Also copy underlying data
inplace: boolean, default False

Returns: renamed: type of caller or None if inplace = True

To link to the CSV file used in the code, click here

Example # 1: replace Boston Celtics command with Omega Warrior in nba.csv file

# import pandas as pd

import pandas as pd

 
# Create data frame from CSV file

df = pd.read_csv ( "nba.csv" )

 
# Print first 10 lines
# dataframe for rendering

df [: 10 ]

Output:

We’re going to change the row indices and double the value.

# this will increase the row index value by two times

df.rename_axis ( lambda x : x * 2 , axis = "index" )

Output:

Example # 2. Changing the column name

# import pandas as pd

import pandas as pd

  
# Create frames ma data from a CSV file

df = pd.read_csv ( "nba.csv" )

  
# this will add & # 39; _X & # 39; at the end of each column name

df.rename_axis ( lambda x: x + " _ X " , axis = "columns" )

Output:

Python | Pandas dataframe.rename_axis () Python functions: Questions

Python | Pandas dataframe.rename_axis () rename: Questions

Shop

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method