About Pandas DataFrame:
Pandas DataFrame — these are rectangular grids that are used to store data. It’s easy to visualize and work with data when stored in a dataFrame.
- It consists of rows and columns.
- Each row is a dimension of some instance, while a column is a vector that contains data for some specific attribute / variable.
- Each data column contains homogeneous data in any specific column, but data rows can contain homogeneous or heterogeneous data in any particular row.
- Unlike a 2D array, the pandas data axes are labeled.
Method # 1: Using the
rename () function. P >
One way to rename columns in a Pandas dataframe is to use the
rename () function. This method is very useful when we need to rename some of the selected columns, because we only need to provide information for the columns that need to be renamed.
Rename one column.
Rename multiple columns.
Method # 2: assigning a list of new column names
Columns can also be renamed by assign by directly assigning the list containing the new names to the
columns attribute of the dataframe object for which we want to rename the columns. The disadvantage of this method is that we need to provide new names for all columns, even if you only want to rename some of the columns.