I was in doubt if I understood completely, so I created a new version of the data and included 3 times Albania with different years to check the result.
import pandas as pd
import io
# Simulando um CSV
s = '''
"Country Name","Country Code","Ano","Pobreza"
"Aruba","ABW","1960",54211
"Afghanistan","AFG","1960",8996351
"Albania","ALB","2017",5643182
"Albania","ALB","1970",1608800
"Andorra","AND","1960",13411
"Albania","ALB","1900",2588
"Angola","AGO","1966",2588
'''
# read csv
df = pd.read_csv(io.StringIO(s), usecols=['Country Name', 'Country Code','Ano',
'Pobreza'])
Now let's "start" the dataframe:
print(df)
Country Name Country Code Ano Pobreza
0 Aruba ABW 1960 54211
1 Afghanistan AFG 1960 8996351
2 Angola AGO 1966 5643182
3 Albania ALB 1970 1608800
4 Andorra AND 1960 13411
5 Albania ALB 1900 2588
6 Albania ALB 2017 2588
Now let's sort in df
by typing the result into a new dataframe ( df2
)
df2 = df.sort_values(['Country Name', 'Ano'])
Finally, let's print the result:
print(df2)
Country Name Country Code Ano Pobreza
1 Afghanistan AFG 1960 8996351
5 Albania ALB 1900 2588
3 Albania ALB 1970 1608800
2 Albania ALB 2017 5643182
4 Andorra AND 1960 13411
6 Angola AGO 1966 2588
0 Aruba ABW 1960 54211
Is that it?