To rename a particular column in pandas in Python, you can use the rename()
function. Here's an example:
main.py321 chars15 lines
This will rename the 'City' column to 'Location' in the DataFrame. The columns
argument of the rename()
function takes a dictionary where the keys are the current column names and the values are the new column names. By setting inplace=True
, the renaming is done directly on the original DataFrame without creating a new one.
The output will be:
main.py104 chars5 lines
gistlibby LogSnag