I have a data frame:
df = pd.DataFrame(data=[[1,2]], columns=['a', 'b'])
I'm aware I can do the following to change all column names in a dataframe:
df.columns = ['d', 'e']
How can I change all column names in a chained operation? For example, I would like to do something like:
df=(
df.rename all column names
.reset_index()
)
The only way I can find is to use df.rename
and build a dictionary with the old and new column pairs but that looks very ugly. Are there any more elegant solutions?
Thanks.