将特定文本数据转换为 Excel 文件

时间:2021-03-23 09:17:27

标签: python excel pandas text xlsx

这是我的文本文件:

enter image description here

我想将其转换为所需附加格式的 Excel 文件,从列标题开始,即数字、类型并忽略该行上方的所有内容。

enter image description here

我已经编写了以下代码,但我没有在 Excel 工作表中获得所需的输出。有人可以提供建议/帮助吗?

from google.colab import files
uploaded = files.upload()
data = []
#example1 = r"C:\Users\SS\Downloads\SM12"
with open('SM12.TXT') as f:
 for line in f:
    data.append([word for word in line.split("\t") if word])
print(data)
import xlwt
wb = xlwt.Workbook()
sheet = wb.add_sheet("New Sheet")
for row_index in range(len(data)):
    for col_index in range(len(data[row_index])):
        sheet.write(row_index, col_index, data[row_index][col_index])
wb.save(r"C:\Users\SS\Downloads\hi.xls")

0 个答案:

没有答案
相关问题