Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas rename index

df.index = df.index.rename('new_index_name')

# Source: https://pandas.pydata.org/docs/reference/api/pandas.Index.rename.html
Comment

dataframe index rename

# For index name:
df = df.rename(index={'old_name': 'new_name'})
# or
df.index = df.index.rename('new_name')
# or 
df.index.rename('new_name', inplace=True)

# For column name:
df = df.rename(columns={'old_name': 'new_name'})
#
df.columns = df.columns.rename('new_name')
# or
df.columns.rename('new_name', inplace=True)
Comment

pandas rename column by index

import pandas as pd
  
# Sample DataFrame
df = pd.DataFrame({'a': [1, 2], 'b': [3, 4]})
  
# Changing columns name with index number
su = df.rename(columns={df.columns[1]: 'new'})
  
# Display
display(su)
Comment

Renaming an index in pandas data frame

df.rename(index={'Republic of Korea':'South Korea'},inplace=True)
Comment

pd df rename along index

df.rename({1: 2, 2: 4}, axis='index')
Comment

PREVIOUS NEXT
Code Example
Python :: how to make a numpy array 
Python :: cool things to do with python 
Python :: blender python select object by name 
Python :: get pixel color pygame 
Python :: pep full form 
Python :: python render_template 
Python :: TypeError: exceptions must derive from BaseException 
Python :: how to define a constant in python 
Python :: set form field disabled django 
Python :: convert string to dictionary python 
Python :: int object is not subscriptable in python 
Python :: set pytesseract cmd path 
Python :: sang nguyen to python 
Python :: how to use google sheet link in pandas dataframe 
Python :: flask return error response 
Python :: create a dataframe python 
Python :: conda env 
Python :: pylint import error 
Python :: replace value in df 
Python :: transpose array python 
Python :: 2 distinct numbers random number generator python 
Python :: get guild by id discord.py 
Python :: python ssl module is not available 
Python :: how to create window in tkinter 
Python :: create spark dataframe from pandas 
Python :: pandas gropu by 
Python :: python delete key from dictionary 
Python :: python file parent 
Python :: how to sort values of pandas dataframe for iqr 
Python :: Adjusting Subplot Margins in Matplotlib 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =