1
commission = 2%,
growth = 10%,
start_price = 100,
current_transaction = 1000

I wanted to create columns (transaction, revenue)

My question is how to create a dataframe with above information for 3 years.

Element Year 1 Year 2 Year 3
Transaction 1100 1210 1331
Revenue 2200 2420 2662

formula for transaction (transaction X growth) e.g(1000 X 10%)

formula for revenue (transaction X commission X price) e.g(1100X 2% X 100)

the year 2 column is outcome of year 1 ..so on.

1 Answer 1

1

This is a classic exponential growth series. You can leverage numpy broadcasting to compute them:

# Convert all percentages into decimals
commission = 0.02
growth = 0.1
start_price = 100
current_transaction = 1000

# We are going to rely on numpy broadcasting to help us do computations on
# arrays
year = np.arange(1,4)
factor = (1 + growth) ** year

# And make the dataframe
df = pd.DataFrame({
    "Transaction": current_transaction * factor,
    "Revenue": current_transaction * factor * commission * start_price
}, index=year).T.add_prefix("Year ")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.