This is the code I used, you need to pass the data I sent as is and just put False for is_supps
def table_to_df():
data = [['', 'Levels', '1', '', '2', '', '3', '', '4', '', '5', '', '6', '', ''], ['Categories', 'Tag / Vers', 'first', 'sec', 'first', 'sec', 'first', 'sec', 'first', 'sec', 'first', 'sec', 'first', 'sec', ''], ['FirstCat', 'Divider1', '6', '7', '2', '3', '8', '8', '6', '7', '2', '4', '8', '8', ''], ['', 'Divider2', '0', '1', '0', '1', '0', '0', '0', '1', '0', '2', '0', '0', ''], ['SecondCat', 'Divider1', '1', '1', '3', '2', '2', '1', '1', '2', '2', '2', '3', '1', ''], ['', 'Divider2', '0', '0', '1', '0', '1', '0', '0', '1', '0', '0', '2', '0', '']]
row_categories = list(row[0] for row in data[2:][::2])
column_subcategories = ['main', 'ref']
severities = data[0][2::2]
severities.pop()
row_index = pd.MultiIndex.from_product([row_categories, ['All', 'Unique']], names=['variant', 'tag'])
column_index = pd.MultiIndex.from_product([severities, column_subcategories], names=['version', 'level'])
df = pd.DataFrame(index=row_index, columns=column_index)
for i in range(2, len(data)):
criteria = data[i][0] if data[i][0] != '' else data[i - 1][0]
row_type = data[i][1]
values = data[i][2:]
for j in range(0, len(severities)):
severity = severities[j]
main_value = values[j * 2]
ref_value = values[(j * 2) + 1]
df.loc[(criteria, row_type), (severity, 'main')] = main_value
df.loc[(criteria, row_type), (severity, 'ref')] = ref_value
df.replace('', pd.NA, inplace=True)
df.fillna(0, inplace=True)
df.loc[(criteria, row_type)].fillna(0, inplace=True)
for category in df.index.levels[0]:
for row_type in df.index.levels[1]:
s = df.loc[(category, row_type)] == 0
if s.all():
df.drop((category, row_type), inplace=True)
try:
df = df.astype(int)
except ValueError:
return df
return df