为数据帧中的每一行找到一个平均值并返回mean resu

2024-09-29 21:57:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我得到了以下DF:http://prntscr.com/f72cbm

def answer():
    Top15 = one()
    timefr = ['2006', '2007', '2008', '2009', '2010', '2011', '2012', '2013', '2014', '2015']
    rng = range(0, 9)
       for i in rng:
           for k,v in Top15[timefr].iloc[[i]].iteritems():
                print(k, v)

函数返回许多以下类型的序列:

2006 Country
China    3.992331e+12
Name: 2006, dtype: float64
2007 Country
China    4.559041e+12
Name: 2007, dtype: float64

年份、国家名称、价值。
我可能会遍历每个系列,将所有值相加,然后将它们除以等等,但是有没有更“潘多拉”的方法呢?
我还想跳过NaN值


Tags: nameincomhttpdfforcountrydtype

热门问题