Why my pandas DataFrame showing only column name

My original DataFrame has the following columns :

df=
     r1           hg1        r9           hg9        r21        hg21     r26       hg26   r32    hg32       r37 hg37    r49 hg49    r52 hg52    r105    hg105   r118    hg118
0   109.103997  0.029037    114.866800  0.000000    93.585901   0.00000 106.478206  0.000000    111.376940  0.000000    81.984848   0.000000    110.608805  0.000000    109.289841  0.060737    106.389980  0.006827    105.775941  0.001492
1   104.398943  0.058043    111.862452  0.000000    90.804183   0.01389 98.849199   0.032482    108.826358  0.040981    80.291790   0.000000    108.184069  0.000000    106.213753  0.167000    103.140119  0.006827    102.727230  0.004468
2   101.588474  0.067700    108.366790  0.000000    88.609266   0.01389 93.517657   0.032482    105.428324  0.053592    78.619017   0.000000    105.082983  0.005768    103.472787  0.235316    101.028560  0.006827    100.553468  0.005960
3   98.545553   0.067700    105.601846  0.009368    87.105383   0.01389 85.366761   0.032482    103.639928  0.053592    77.153464   0.030494    103.223035  0.005768    100.396127  0.242896    98.318994   0.013678    97.497147   0.005960
4   96.181582   0.067700    103.472787  0.009368    85.537507   0.01389 81.155126   0.032482    99.231445   0.066203    75.831122   0.060886    100.004874  0.005768    97.201738   0.242896    93.859710   0.013678    94.342876   0.005960

I want to plot all the columns starting with r_ on one axis and hg_ on other axes. To achieve this, I need to re-shape data in a DataFrame with 3 columns: sample, radius and Hg_vol. For this, I save data in a new DataFrame DF:

But my new DataFarme only shows the new column’s name, i.e. sample radius Hg_vol. May I know where I am making mistakes in code here

samples = list(set([col.replace('r', '').replace('hg', '') for col in df.columns]))

DF = pd.DataFrame(columns = ['sample', 'radius', 'Hg_vol'])

for sample in samples:
    df_tmp = pd.DataFrame()
    for col in df.columns:          
        if f's{sample}_' in col:
            df_tmp['sample'] = len(df[col])*[sample]
            if col.startswith('r'):
                df_tmp['radius'] = df[col]
            else:
                df_tmp['Hg_vol'] = df[col]
        DF = DF.append(df_tmp)

DF['sample'] = DF['sample'].astype(int)
DF = DF.sort_values(by = 'sample', ignore_index = True)
DF['sample'] = DF['sample'].astype(str)
DF

Answer

You can reshape using pandas.wide_to_long:

df2 = pd.wide_to_long(df.reset_index(), stubnames=['r', 'hg'], i='index', j='n')

output:

>>> df2.reset_index().head()
   index  n           r        hg
0      0  1  109.103997  0.029037
1      1  1  104.398943  0.058043
2      2  1  101.588474  0.067700
3      3  1   98.545553  0.067700
4      4  1   96.181582  0.067700

Then plot, for example, with seaborn.scatterplot:

import seaborn as sns
sns.scatterplot(data=df2.reset_index(), x='r', y='hg', hue='n')

seaborn scatterplot

alternatively, as category:

import seaborn as sns
sns.scatterplot(data=df2.reset_index().astype({'n': 'category'}),
                x='r', y='hg', hue='n')

seaborn scatterplot categorical