user13924616
user13924616

Reputation:

How to calculate the Revenue growth with Pandas?

I want to calculate the revenue growth for a set of companies.

My Data basically looks like this:

    Year    Name                Sales   Revenue Growth
0   2010.0  SHUTTERSTOCK INC    829730.0    0
1   2011.0  SHUTTERSTOCK INC    1202710.0   0
2   2012.0  SHUTTERSTOCK INC    1696160.0   0
3   2013.0  SHUTTERSTOCK INC    2355150.0   0
4   2014.0  SHUTTERSTOCK INC    3279710.0   0

The formula for Revenue Growth is (Sales t - Sales t-1) / sales (t-1). t and t-1 are only referring to the time indices. Can anyone help me how to implement it?

Thanks in advance.

Upvotes: 1

Views: 1256

Answers (1)

ipj
ipj

Reputation: 3598

There is useful function pct_change() to do this:

df['Revenue Growth'] = df.Sales.pct_change()

result:

     Year              Name      Sales  Revenue Growth
0  2010.0  SHUTTERSTOCK INC   829730.0             NaN
1  2011.0  SHUTTERSTOCK INC  1202710.0        0.449520
2  2012.0  SHUTTERSTOCK INC  1696160.0        0.410282
3  2013.0  SHUTTERSTOCK INC  2355150.0        0.388519
4  2014.0  SHUTTERSTOCK INC  3279710.0        0.392569

It translates to: df.Sales/df.Sales.shift() - 1.

Upvotes: 2

Related Questions