python 數據處理3----讀取txt 一列數據寫入excel 文件

我們在做大數據測試分析的時候,經常需要用到excel 統計分析數據,以下例子就是

python 調用xlwt 寫excel 文件:

import sys
import random
import time
import xlwt
import codecs

def Txt_to_Excel(ws,inputTxt,start_row,start_col):
	fr = codecs.open(inputTxt,'r')
	line_number = 0
	row_excel = start_row
	for line in fr:
		#print(line)
		line_number +=1
		row_excel +=1
		line =line.strip()
		#print(line)
		line =line.split()
		#print(line)
		b =line[3:4]
		#print(b)
		col_excel =start_col;
		ws.write(row_excel,col_excel,b)
		

if __name__ == '__main__':
	outputfile ='excel_result1.xls'
	sheet_name1='rnnoise'
	sheet_name2='nsdk'
	wb = xlwt.Workbook(encoding = 'utf-8')
	ws1 = wb.add_sheet(sheet_name1)
	ws2 = wb.add_sheet(sheet_name2)
	startrow =0
	
	dir1 = './0db/pesq_results1.txt'
	startcol1 =0
    Txt_to_Excel(ws1,dir1,startrow,startcol1)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章