visibility 7 comment 0 access_time 21 days 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.

Output:

2022090404325-image.png

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)
print(df)

# Rename columns
df.columns = ['a','b']
print(df)
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.