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 index values

df.rename(index={'alpha': 'mu'})
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 :: count missing values groupby 
Python :: python print dictionary line by line 
Python :: removing odd index character of a given string in python 
Python :: python zip lists into dictionary 
Python :: write txt python 
Python :: none address in python 
Python :: t.interval scipy 
Python :: access dataframe column with space 
Python :: python read text file into a list 
Python :: python encrypt password 
Python :: replacing values in pandas dataframe 
Python :: python open dicom file 
Python :: check cuda available tensorflow 
Python :: conda python-telegram-bot 
Python :: print without changing line python 
Python :: native bold text 
Python :: python print time difference 
Python :: how to set required drf serialzier 
Python :: flatmap python 
Python :: web scraping linkedin profiles python jupyter 
Python :: Python program to check leap year or not? 
Python :: write specific columns to csv pandas 
Python :: opencv imshow resize 
Python :: python transfer file 
Python :: not importing local folder python 
Python :: update python in cmd 
Python :: remover espaços string python 
Python :: captain marvel subtitles subscene 
Python :: python tkinter delete label 
Python :: update windows wallpaper python 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =