I was trying to write to excel sheet by using panda which I successfully did. I have to questions: First I have tried to sort by column but I couldn't. I used df.sort_index, df.sortlevel both did not get what I want. this my code:
df = DataFrame({'Seq Label':['if >= 1','if >= 2','if >= 3','if >= 4','if >= 5','if >= 6','if >= 7'],
'TP':[countTP, twocountTP, threecountTP, fourcountTP, fivecountTP, sixcountTP, sevencountTP],
'TN':[countTN, twocountTN, threecountTN, fourcountTN, fivecountTN, sixcountTN, sevencountTN],
'FP':[countFP, twocountFP, threecountFP, fourcountFP, fivecountFP, sixcountFP, sevencountFP],
'FN':[countFN, twocountFN, threecountFN, fourcountFN, fivecountFN, sixcountFN, sevencountFN]})
df.to_excel('Book10.xlsx', sheet_name='sheet1', index=False)
It gives me this output which I don't want:
FN FP Seq Label TN TP
0 123 125 if >= 1 20296 7671
1 123 125 if >= 2 17142 6274
2 123 125 if >= 3 3810 1307
3 7 11 if >= 4 419 213
4 1 4 if >= 5 127 74
5 0 0 if >= 6 0 0
6 0 0 if >= 7 0 0
I want it sort table as the order I have in my df in the code. I want it sort it as:
Seq Label TP TN FP FN
Second Question How to write on an existing excel sheet without deleting or writing on other data. I have tried to use different libs. such as
import pandas as pd
import openpyxl
import xlrd
I am sorry if I make it too long. I need your help Thanks
