Rename Columns in Pandas DataFrame

Kontext Kontext event 2022-09-04 visibility 154
more_vert

Code description

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)
More from Kontext
comment Comments
No comments yet.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts