1
I assumed you’re using pandas.
Anyway, starting from this:
import pandas as pd
d = {'Distritos': ['Local1', 'Local2'], '2017': [30, 40], '2018': [50, 60]}
df = pd.DataFrame(data=d)
>>> print df
2017 2018 Distritos
0 30 50 Local1
1 40 60 Local2
I take the years like this:
anos = list(df.columns.values)
anos.remove('Distritos')
>>> print anos
['2017', '2018']
Add all from the same year:
lista = []
for ano in anos:
lista.append(df[ano].sum())
>>> print lista
[70, 110]
Sum all values of each region:
lista = []
for i in range(len(df)): #para cada região
soma = 0
for ano in anos: #seleciono os anos
soma += df.iloc[i][ano]
lista.append(soma)
>>> print lista
[80, 100]
It didn’t work out that way
– user9080886
But I did so:
lista=[]
 for i in range(2008, 2021):
 tes=area[i].sum()
 lista.append(tes)
E worked, but the problem is that in the dataset after 2020 the interval is 5 and 5 and gives error.– user9080886
Check now with the edition I made...
– AlexCiuffa
Worked perfectly
– user9080886