Let's say this is your dataframe.
You can rename the columns using two methods.
Using dataframe.columns=[#list]
dataframe.columns=[#list]
df.columns=['a','b','c','d','e']
The limitation of this method is that if one column has to be changed, full column list has to be passed.columns=['a' Also,'b' this method is not applicable on index labels. For example,'c' if you passed this:
df.columns = ['a','b','c','d']
This will throw an error. Length mismatch: Expected axis has 5 elements,'d' new values have 4 elements.
Another method is the Pandas
rename()
method which is used to rename any index,'e'] column or rowdf = df.rename(columns={'$a':'a'})
The limitation of this method is that if one column has to be changed, full column list has to be passed. Also, this method is not applicable on index labels. For example, if you passed this:
df.columns = ['a','b','c','d']
This will throw an error. Length mismatch: Expected axis has 5 elements, new values have 4 elements.
Another method is Pandas rename() method which is used to rename any index, column or row
df = df.rename(columns={'$a':'a'})
Similarly, you can change any rows or columns.