如何用python,将print的结果导入到excel表格中

将printprint(ppi.scorePPITreesP(proteinsA, proteinsB))的结果导入到excel表格中

import numpy as np
from matplotlib import pyplot as plt
import PPI as ppi
from sklearn import manifold



# Fanconia Anemia proteins files, D2.fasta, L.fasta,
# shall exist in the sub-folder ./PPIData. These files contain the corresponding protein sequences from Fanconia Anemia
proteinNames = ['FANCE1020_1080', 'FANCD21_60', 'FANCD260_120']
n = len(proteinNames)
n = len(proteinNames)

distM = np.zeros([n, n])
distV = []

for i in range(0, n):
    nameA = proteinNames[i]
    proteinsA = ppi.getAllSequences(nameA)  # The Fanconi Anemia file: one file contain the same protein for different geneomes
    print(nameA, len(proteinsA))

    for j in range(0, n):
        nameB = proteinNames[j]
        proteinsB = ppi.getAllSequences(nameB)
        print(nameB, len(proteinsB))
        dist = 1 - ppi.scorePPITreesP(proteinsA, proteinsB)
        distV.append(dist)
        distM[i, j] = dist
        print(nameA, nameB, dist)
        print(ppi.scorePPITreesP(proteinsA, proteinsB))
print(distM)
print()


使用xlwt模块

1
2
3
4
import xlwt
workbook = xlwt.Workbook()
sheet = workbook.add_sheet("Sheet Name")
sheet.write(0, 0, 'foobar') # row, column, value
最后一行就是写入,把你要print的内容write进去就行了

https://blog.csdn.net/weixin_41770169/article/details/90053602