I am new to Pandas and see that there are numerous ways to change column headers.
For example, the set_axis
command works like this :
>>> import pandas as pd
>>> import numpy as np
>>> df = pd.DataFrame(np.arange(3),columns=['a'])
>>> df
a
0 0
1 1
2 2
>>> df["a"][0]
0
>>> df.set_axis(['A'],axis=1,inplace=True)
>>> df
A
0 0
1 1
2 2
>>> df["A"][0]
0
EDIT : Alternatively, one can use
df.columns = ['A']
to change the column name.
But now, it seems that if I want to change the column header for display purposes only (because the header label is inconvenient to use as a dictionary key), I have to create an entirely new data frame :
>>> df_pretty = df.set_axis(['Long label (%)'],axis=1,inplace=False)
df_pretty
Long label (%)
0 0
1 1
2 2
Is this right? Or am I missing something? It seems a waste of memory to have to recreate a new data frame just for printing. I would have thought that Pandas would have a way to store an internal "key" and a separate column label, used only for display purposes.