我有一个 DataFrame df,其中包含 2014 年到 2018 年的一些国家统计数据。一些国家/地区每年都有值,而一些国家/地区缺少一些。DataFrame 如下所示:
countryName 2014 2015 2016 2017 2018
Afghanistan .. .. 281 .. ..
Albania .. .. .. 891 901
Algeria 791 801 804 817 820
...
我只想保留最新的数据值,所以对于上面的 DataFrame,结果应该是:
countryName value
Afghanistan 281 # the most recent value from 2016
Albania 901 # the most recent value from 2018
Algeria 820 # the most recent value from 2018
...