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

how to rename rengeindex pandas

df1.rename(index={0: 'a', 1:'b'})
Comment

pd df rename along index

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

PREVIOUS NEXT
Code Example
Python :: python windows hide files 
Python :: python link shortener 
Python :: python cv2 read image grayscale 
Python :: Cannot convert non-finite values (NA or inf) to integer 
Python :: python typing as int or float 
Python :: how to get ip address of pc using python 
Python :: jupyter clear cell output programmatically 
Python :: save df to txt 
Python :: standardscaler into df data frame pandas 
Python :: drop rows that contain null values in a pandas dataframe 
Python :: check numpy version 
Python :: dataframe find nan rows 
Python :: reverse row order pandas 
Python :: classification report scikit 
Python :: python schedule timezone 
Python :: tkinter listbox delete all items 
Python :: python pip install jinja 
Python :: python mean and standard deviation of list 
Python :: what is self in programming 
Python :: how to wait in python 
Python :: numpy fill na with 0 
Python :: discord.py intents 
Python :: python join array of ints 
Python :: tensorflow load h5 model 
Python :: python os if file exists 
Python :: colab cuda version 
Python :: pandas percent change between two rows 
Python :: open website python 
Python :: favicon django 
Python :: opencv get area of contour 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =