Pandas: What does the compound method is useful for?

Pandas: What does the compound method is useful for?



I found pandas compound dataframe method documentation but it is really terse. I've tried to run it on a simple dataframe, but didn't understand its utility. Here is my example:


In [5]: df = pd.DataFrame(np.arange(6).reshape(3,2), columns=['a', 'b'])

In [6]: df
Out[6]:
a b
0 0 1
1 2 3
2 4 5

In [7]: df.compound()
Out[7]:
a 14
b 47
dtype: int32



What should I use this method for?






Column a means you earn 0% the first year, 200% the second year and 400% the third, for a total of 15x the original amount, or an increase of 1400%. Time units are made up.

– Mad Physicist
Sep 10 '18 at 4:02



a






Its the same as df.a.add(1).cumprod().sub(1) . You can see the compounding evolving, and .compound() yields just the last number

– RafaelC
Sep 10 '18 at 4:04


df.a.add(1).cumprod().sub(1)


.compound()




1 Answer
1



This is more like loan calculation -- compound interest



enter image description here


df.compound()
Out[143]:
a 14
b 47
dtype: int32



So for columns a


a



enter image description here






Ops, I could have just ctrl-click to see the source: (1 + self).prod(axis=axis, skipna=skipna, level=level) - 1

– neves
Sep 11 '18 at 13:39


(1 + self).prod(axis=axis, skipna=skipna, level=level) - 1



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế