Python | Pandas Dataframe.rename() Last Updated : 17 Sep, 2018 Comments Improve Suggest changes Like Article Like Report Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas rename() method is used to rename any index, column or row. Renaming of column can also be done by dataframe.columns = [#list]. But in the above case, there isn't much freedom. Even if one column has to be changed, full column list has to be passed. Also, the above method is not applicable on index labels. Syntax: DataFrame.rename(mapper=None, index=None, columns=None, axis=None, copy=True, inplace=False, level=None) Parameters: mapper, index and columns: Dictionary value, key refers to the old name and value refers to new name. Only one of these parameters can be used at once. axis: int or string value, 0/'row' for Rows and 1/'columns' for Columns. copy: Copies underlying data if True. inplace: Makes changes in original Data Frame if True. level: Used to specify level in case data frame is having multiple level index. Return Type: Data frame with new names To download the CSV used in code, click here. Example #1: Changing Index label In this example, the name column is set as index column and it's name is changed later using the rename() method. Python 1== # importing pandas module import pandas as pd # making data frame from csv file data = pd.read_csv("nba.csv", index_col ="Name" ) # changing index cols with rename() data.rename(index = {"Avery Bradley": "NEW NAME", "Jae Crowder":"NEW NAME 2"}, inplace = True) # display data Output: As shown in the output image, the name of index labels at first and second positions were changed to NEW NAME & NEW NAME 2. Example #2: Changing multiple column names In this example, multiple column names are changed by passing a dictionary. Later the result is compared to the data frame returned by using .columns method. Null values are dropped before comparing since NaN==NaN will return false. Python3 1== # importing pandas module import pandas as pd # making data frame from csv file data = pd.read_csv("nba.csv", index_col ="Name" ) # changing cols with rename() new_data = data.rename(columns = {"Team": "Team Name", "College":"Education", "Salary": "Income"}) # changing columns using .columns() data.columns = ['Team Name', 'Number', 'Position', 'Age', 'Height', 'Weight', 'Education', 'Income'] # dropna used to ignore na values print(new_data.dropna()== data.dropna()) Output: As shown in the output image, the results using both ways were same since all values are True. Comment More infoAdvertise with us Next Article Python | Pandas Dataframe.rename() K Kartikaybhutani Follow Improve Article Tags : Misc Python Python-pandas Python pandas-dataFrame Pandas-DataFrame-Methods +1 More Practice Tags : Miscpython Similar Reads Pandas dataframe.nunique() Method Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas DataFrame.nunique Syntax Pandas dataframe.nunique() function returns a Series 2 min read Python | Pandas Series.isnull() Pandas series is a One-dimensional ndarray with axis labels. The labels need not be unique but must be a hashable type. The object supports both integer and label-based indexing and provides a host of methods for performing operations involving the index. Pandas Series.isnull() function detect missi 2 min read Python | Pandas dataframe.isna() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas dataframe.isna() function is used to detect missing values. It return a boolean 2 min read Python | Pandas DataFrame.fillna() to replace Null values in dataframe Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Sometimes csv file has null values, which are later displayed as NaN in Data Frame. Ju 5 min read Python | Pandas dataframe.clip() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas dataframe.clip() is used to trim values at specified input threshold. We can us 3 min read Pandas DataFrame.columns In Pandas, DataFrame.columns attribute returns the column names of a DataFrame. It gives access to the column labels, returning an Index object with the column labels that may be used for viewing, modifying, or creating new column labels for a DataFrame.Note: This attribute doesn't require any param 2 min read Pandas Dataframe.sort_values() In Pandas, sort_values() function sorts a DataFrame by one or more columns in ascending or descending order. This method is essential for organizing and analyzing large datasets effectively.Syntax: DataFrame.sort_values(by, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last') 2 min read Python | Pandas Series.value_counts() Pandas is one of the most widely used library for data handling and analysis. It simplifies many data manipulation tasks especially when working with tabular data. In this article, we'll explore the Series.value_counts() function in Pandas which helps you quickly count the frequency of unique values 2 min read Python | Pandas DataFrame.nlargest() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas nlargest() method is used to get n largest values from a data frame or a series 2 min read Python | Pandas DataFrame.nsmallest() Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.Pandas nsmallest() method is used to get n least values from a data frame or a series. 2 min read Like