stateList = [['Set', 'state', 2022, 2023, 2024], ['A', 'start', 100, 100, 100],['A', 'end', 110, 100, 90]]
def get_changes(state_list):
starts = {}
ends = {}
# first build a dictionary of start and end states for each state (A, B, ...)
for state in stateList:
if state[1] == 'start':
starts[state[0]] = state
elif state[1] == 'end':
ends[state[0]] = state
state_changes = []
# iterate through each state name
for state_name in starts.keys():
# calculate column changes as (end-start)/start*100
# first two columns are ignored
column_changes = [(ends[state_name][i] - v)/v*100 for i, v in enumerate(starts[state_name]) if i > 1]
# build the state change list
state_changes.append([state_name, 'change', *column_changes])
return state_changes
print(get_changes(stateList))
To embed this project on your website, copy the following code and paste it into your website's HTML: