I am trying to add meta information to each column of a pandas dataframe. For example I import measurement data like this:
columns = ['Relative_Pressure','Volume_STP']
df = pd.read_csv(StringIO(contents), skiprows=4, delim_whitespace=True,index_col=False,header=None)
df.columns = columns
df.drop(df.index[-1], inplace=True)
where contents
is a string in csv format. This results in a pandas dataframe that looks e.g. like this:
Now I would like to add the respective units for every column of the dataframe and maybe also an additional description.
I saw this answer and tried to implement it like this:
df['Relative_Pressure'].unit = '-'
df['Relative_Pressure'].descr = 'p/p0'
df['Volume_STP'].unit = 'ccm/g'
df['Volume_STP'].descr = 'Additional info'
However this does not seem to change the Dataframe in any sense. When I print it again it looks exactly the same as before.
What would be a correct way to add metadata to the columns of the Dataframe or if I added the meta data correctly how can I display it?
EDIT: What is shown here would be very similar to what I would like to achieve, however I am not sure how I can do this with first importing the data and then adding the variable name rows.