pandas :将DataFrame的最后一行除以第一行 [英] pandas: Divide DataFrame last row by first row

查看:155
本文介绍了 pandas :将DataFrame的最后一行除以第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题类似于 Python:Pandas将DataFrame按第一行划分

我有一个看起来像这样的DataFrame:

I have a DataFrame which looks like this:

            1125400  5430095  1095751
2013-04-02    98.91      NaN  5626.79
2013-04-03    99.29      NaN  5727.53
2013-04-04    99.79      NaN  5643.75
2013-04-07   100.55      NaN  5630.78
2013-04-08   100.65      NaN  5633.77

我想将最后一行的值除以第一行的值,以便获得随时间变化的百分比差异.

I would like to divide the values of the last row by the values of the first row in order to obtain the percentage difference over time.

推荐答案

只需取第一行和最后一行的值,然后将它们相除即可,如下所示:df.T[df.index[0]] / df.T[df.index[-1]]

Just take the first row and the last row values, then divide them, like this: df.T[df.index[0]] / df.T[df.index[-1]]

这篇关于 pandas :将DataFrame的最后一行除以第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆