So I need my output to look like this: output
The final question will be: How do I go about adding the values of each column to the rowstring?
I'm defining a function that formats how the lines will print, it looks like this:
def line_string(row_title, row_data, data_type):
row_title = f"{row_title:38}"
row_string = row_title
columns = years[-1]
for column in range(columns+1):
# Concatenate row_string per the data_type function arugment as per below
# Make each of the data columns 9 characters wide
# If data_type equals "decimal", then format as decimal with the specified width
if data_type == "integer":
row_string = row_string + f"{row_data[column]:9,}"
elif data_type == "decimal":
row_string = row_string + f"{row_data[column]:9,.2f}"
elif data_type == "percent":
row_string = row_string + f"{row_data[column]:9,.2%}"
return row_string
# this is a test:
line_string("Cumulative sum", cumulatitve_sum, "decimal")
I get this error though:
TypeError Traceback (most recent call last)
in
44 return row_string
45
---> 46 line_string("Cumulative sum", cumulatitve_sum, "decimal")
in line_string(row_title, row_data, data_type)
35 elif data_type == "decimal":
---> 36 row_string = row_string + f"{row_data[column]:9,.2f}"
37
TypeError: 'function' object is not subscriptable
How do I go about adding the values of each column to the rowstring?