To rename the columns of a Pandas DataFrame in Python, you can use the rename function. The rename function takes a dictionary as input, where the keys are the original column names, and the values are the new column names. Here's an example:
main.py300 chars16 lines
This will output:
main.py128 chars5 lines
In this example, we created a sample DataFrame with three columns col1, col2, and col3. We then used the rename method to rename the columns to new_col1, new_col2, and new_col3. Finally, we printed the updated DataFrame with the new column names.
gistlibby LogSnag