import xlwt
import pandas as pd
import numpy as np
import os
#创建txt
def txt_create(path_txt,num, val):
file = open(path_txt + '/' + 'gauge_%s.txt' % num, 'w')
for i in val:
file.write(str(i)+'\r\n')
path_txt = './txt'
path = './test.xls'
if not os.path.exists(path_txt):
os.makedirs(path_txt)
#读取excel数据
df = pd.read_excel(path)
data = []
for rows in range(df.shape[0]):
data.append(df.ix[rows].values)
#创建名字
num_list = []
for i in range(1,34):
for j in range(1,31):
num = ('%02d' + '%02d') %(i, j)
num_list.append(num)
#同时遍历名字和每一行数据,创建txt
for (num, val) in zip(num_list, data):
txt_create(path_txt, num, val)
python 读取excel数据并写入txt
最新推荐文章于 2023-08-16 10:43:47 发布