Я хочу получить сумму в последнем столбце (ie., Столбец "E") и добавить его в качестве нижнего колонтитула. Как это сделать? Я не нашел никакой специфической c функции для того же самого. Хотя я нашел похожий пост, который не помог.
def printCSVRow(argument1, argument2, argumentSwitch):
arguement1_output = None
arguement2_output = None
prettyTable.title = 'B1 and B2 values'
if argument1 is not None:
arguement1_output = argument1.split("\n")[1].split(";")
if argumentSwitch == 1:
row = ["B1"]
row += arguement1_output
prettyTable.add_row(row)
else:
row = ["B2"]
row += arguement1_output
prettyTable.add_row(row)
if argument2 is not None:
arguement2_output = argument2.split("\n")[1].split(";")
if argumentSwitch == 1:
row = ["B2"]
row += arguement2_output
prettyTable.add_row(row)
else:
row = ["B1"]
row += arguement2_output
prettyTable.add_row(row)
def csvHeader(B1):
headerNames = ["type"]
headerNames += B1.split("\n")[0].split(";")
prettyTable.field_names = headerNames
if __name__ == '__main__':
Handler = main()
B1 = Handler.run()
B2 = None
B3 = None
csvHeader(B1)
iteration = 0
while True:
B3 = Handler.run(B1)
if B3 == B2:
printCSVRow(B1,B2, 1)
print(prettyTable)
else:
B2 = B1
B1 = B3
вывод:
+---------------------------------------------------------------------------------------------------+
| B1 and B2 values |
+------+--------+--------+------+-------+--------+------+-----------------+-----------------+-------+
| type | id1 | start1 | end1 | id2 | start2 | end2 | subseqDP | hybridDP | E |
+------+--------+--------+------+-------+--------+------+-----------------+-----------------+-------+
| B1 | target | 87 | 93 | query | 24 | 30 | CAAGGGU&ACCCUUG | (((((((&))))))) | -3.62 |
| B2 | target | 39 | 45 | query | 98 | 104 | UCCUGGA&UCCAGGA | (((((((&))))))) | -4.37 |
+------+--------+--------+------+-------+--------+------+-----------------+-----------------+-------+
Ожидаемый вывод:
+---------------------------------------------------------------------------------------------------+
| B1 and B2 values |
+------+--------+--------+------+-------+--------+------+-----------------+-----------------+-------+
| type | id1 | start1 | end1 | id2 | start2 | end2 | subseqDP | hybridDP | E |
+------+--------+--------+------+-------+--------+------+-----------------+-----------------+-------+
| B1 | target | 87 | 93 | query | 24 | 30 | CAAGGGU&ACCCUUG | (((((((&))))))) | -3.62 |
| B2 | target | 39 | 45 | query | 98 | 104 | UCCUGGA&UCCAGGA | (((((((&))))))) | -4.37 |
+------+--------+--------+------+-------+--------+------+-----------------+-----------------+-------+
| Total | -7.99|
+------+--------+--------+------+-------+--------+------+-----------------+-----------------+-------+