Я заново создал ваши данные (В следующий раз предоставьте данные, а не изображение) и сделал это:
import pandas as pd
# Read the file
df = pd.read_excel(r'Data/Stackoverflow_04_25.xlsx', header=[0,1])
# 'break' the levels in the colum names
df.columns = ['_'.join(col)for col in df.columns]
# Rename some of the columns
df = df.rename(columns = {'ID_Unnamed: 0_level_1':'ID','COUNTRY _Unnamed: 1_level_1':'Country','NAME_Unnamed: 2_level_1':'Name'})
# Generate a new 'final' dataframe
df_ = pd.DataFrame(columns = ['ID', 'Country', 'Name'])
# loop over the columns of interes an add the result to the final df
for column in ['4/1_Type2', '4/1_Type3' , '4/2_Type1', '4/2_Type2' ,'4/2_Type3']:
df1 = df.groupby(['ID', 'Country', 'Name'], as_index = False)[column].first().rename(columns = {column:'Counts'})
df1.loc[:,'Date'] = column[:3]
df1.loc[:,'Type'] = column[-5:]
df_ = pd.concat([df_, df1], 0, sort = True).reset_index(drop = True)
# Order the final dataframe columns
df_ = df_[['ID', 'Country', 'Name', 'Type', 'Date', 'Counts']]
df_
Что выглядит очень похоже на то, что вы хотите.Надеюсь, что это работает.
ID Country Name Type Date Counts
0 1 A D Type2 4/1 0.0
1 2 B E Type2 4/1 0.0
2 3 C F Type2 4/1 5.0
3 1 A D Type3 4/1 10.0
4 2 B E Type3 4/1 5.0
5 3 C F Type3 4/1 15.0
6 1 A D Type1 4/2 10.0
7 2 B E Type1 4/2 10.0
8 3 C F Type1 4/2 10.0
9 1 A D Type2 4/2 0.0
10 2 B E Type2 4/2 10.0
11 3 C F Type2 4/2 10.0
12 1 A D Type3 4/2 0.0
13 2 B E Type3 4/2 0.0
14 3 C F Type3 4/2 10.0