Rename Columns in Pandas DataFrame
Code description
This code snippet provides a simple approach to rename column names in a Panda DataFrame. It directly sets DataFrame.columns
property.
Output:
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)
copyright
This page is subject to Site terms.
comment Comments
No comments yet.