排明智的文本文件在Excel中我有去像一個Excel文件:寫入文件使用python
208324_at akp13_human 7 6.9 5.8 5 7 5.7
208325_s_at akp13_human 25.5 21.3 9.9 9 13.1 8.5
我一定要找到每個值的日誌,並將其寫入到另一個文本文件。以下是代碼:
import xlrd
from xlrd import open_workbook, XL_CELL_TEXT
import math
filename = "log_values.txt"
computed_value = []
i = 0
with open_workbook("log10wholetest.xlsx") as f:
sheet = f.sheet_by_index(0)
n = sheet.nrows
for i in range(0, n-1):
a = sheet.row_values(i)
b = map(float, a)
for line in b :
log = math.log10(float(line))
computed_value.append(log)
i += 1
with open(filename, 'w') as g:
for value in computed_value :
g.write("%s\t" % value)
這讓我有絡繹不絕類似的結果的文本文件:
2.55750720191 2.53995384166 2.21827285357
等。 但我希望將結果打印爲行,因爲文件的第2行的日誌值應該從第二行開始(在結果文件中),依此類推。 如果這是一個非常簡單的問題,我很抱歉,但我對python完全陌生。
我很確定你的代碼沒有按照你的意圖格式化。 – sberry
亞..我意識到..謝謝 – RKundra
當我回到atba電腦時,我會回答,但基本上你需要每行創建一個列表,並將該列表追加到你的computer_value列表中。然後,您將迭代每行值,以便它們位於不同的行上。 – sberry