How-to’s¶
How to run all versions?
Run all versions from the runplan:
import os
from input import runplan
for v in runplan.data["version"]:
os.system(f"python run.py --version {v}")
How to pretty-print the output data frame?
Print all rows and columns of the output
data frame with 2 decimal places:
import os
import pandas as pd
from cashflower import run
from settings import settings
pd.options.display.float_format = '{:.2f}'.format
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)
pd.set_option('display.width', 1000)
if __name__ == "__main__":
output = run(settings=settings, path=os.path.dirname(__file__))
print(output.to_string(index=False))
How to loop through all records of a model point?
To iterate over all records of a model point, use fund.model_point_data.shape[0]
as the upper bound:
@variable()
def total_fund():
total = 0
for i in range(fund.model_point_data.shape[0]):
total += fund.get("fund_value", i)
return total
This code loops through each record and sums the fund_value
for all records of the model point.