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

pd df rename along index

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

PREVIOUS NEXT
Code Example
Python :: start django project 
Python :: python for i in directory 
Python :: how to redirect to another page in django after login 
Python :: Feature importance Decision Tree 
Python :: how to sharpen image in python using cv2 
Python :: emacs region indent python 
Python :: print nested list in new lines 
Python :: exact distance 
Python :: when pyspark 
Python :: number guessing game python 
Python :: browser refresh selenium python 
Python :: plotly scatter markers size 
Python :: twilio python 
Python :: splitting a string and appending each character to a list python 
Python :: standard module 
Python :: remove substring python 
Python :: plot tf model 
Python :: python rock paper scissor 
Python :: kivy changing screen in python 
Python :: polarean share price 
Python :: python number with comma to float 
Python :: Test Speed internet using Python 
Python :: how to empty a text file in python 
Python :: pandas sort values group by 
Python :: python os exists 
Python :: get all files within multiple directories python 
Python :: reload is not defined python 3 
Python :: filter list dict 
Python :: 1052 uri solution 
Python :: add percentage column pandas 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =