visibility 24 comment 0 access_time 6 months ago language English

codeRename Columns in Pandas DataFrame

This code snippet provides a simple approach to rename column names in a Panda DataFrame. It directly sets DataFrame.columns property.



Code snippet

import pandas as pd

data = {}
data['A'] = [1,2,3,4,5]
data['B'] = ['A','B','C','D','E']
df = pd.DataFrame(data)

# Rename columns
df.columns = ['a','b']
fork_right Fork
copyright This page is subject to Site terms.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

comment Comments
No comments yet.