Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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

rename column by indexing

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

PREVIOUS NEXT
Code Example
Python :: python stack data structure 
Python :: pandas add prefix zeros to column values 
Python :: uses specific version python venv 
Python :: how to strip white space of text in python? 
Python :: creating new virtual environment in python 
Python :: numpy set nan to 0 
Python :: pandas df to list of dictionaries 
Python :: swap in python 
Python :: executing curl commands in python 
Python :: python subset 
Python :: python checking for NoneType 
Python :: len in python 
Python :: how to add createsuper user in django 
Python :: raw input example python 
Python :: send api request python 
Python :: dataframe of one row 
Python :: change month name in python 
Python :: python program to find second largest number in a list 
Python :: raise 400 error python 
Python :: name, *line = input().split() 
Python :: python escape character example 
Python :: python replace one character into string 
Python :: Python Tkinter PanedWindow Widget 
Python :: concatenation of array in python 
Python :: make_response is not defined django 
Python :: python convert ascii to char 
Python :: python get name of vlue 
Python :: how to set pandas dataframe as global 
Python :: how to add labels on bar of barchart seaborn 
Python :: python for loop index 
ADD CONTENT
Topic
Content
Source link
Name
3+3 =