I'm trying to print a simple table with 3 columns: Date, Market Return, and Final value. I'm having a hard time getting the syntax correct to both align a column right or left AND format a number - as decimal or percent:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
investment = 10000
expected_returns = 0.06
volatility = 0.14
duration = 20
sip = 10000
print(f'{"Date":<5}{"Return":>10}{"Value":>12}')
for date in range(duration):
market_return = np.random.normal(expected_returns, volatility)
final_value = sip + (1+ market_return)* investment
print(f'{date:<5.0f}{market_return:>10.1f}{final_value:>10.0f}')
investment = final_value
So the first column is 5 characters wide (left-aligned) and the 2nd and 3rd are 10 and 12 characters wide respectively - both right-aligned.
I am assuming I don't need to use the tab control "\t"? so the total characters of the print range should be 5+10+12=27.
The print statement outside the function executes fine.
Thx in advance.