Python实现txt转Excel(坐标)

python 复制代码
import pandas as pd

def txt_to_excel(txt_file, excel_file):
    # 读取 txt 文件
    with open(txt_file, 'r') as f:
        lines = f.readlines()

    # 将每行数据分割成多个单元格
    data = []
    for line in lines:
        row = line.strip().split(' ')
        data.append(row)

    # 将数据保存到 Excel 文件
    df = pd.DataFrame(data)
    df.to_excel(excel_file, index=False, header=False)

# 文件名
file_name = '100-100圆柱'

# 调用函数,传递变量作为参数
txt_to_excel(file_name+'.txt', file_name+'.xlsx')

图示

相关推荐
田姐姐tmner20 分钟前
Python切片
开发语言·python
t***316535 分钟前
爬虫学习案例3
爬虫·python·学习
AI小云1 小时前
【数据操作与可视化】Pandas数据处理-其他操作
python·pandas
大佬,救命!!!1 小时前
更换适配python版本直接进行机器学习深度学习等相关环境配置(非仿真环境)
人工智能·python·深度学习·机器学习·学习笔记·详细配置
无心水2 小时前
【Python实战进阶】4、Python字典与集合深度解析
开发语言·人工智能·python·python字典·python集合·python实战进阶·python工业化实战进阶
上班职业摸鱼人2 小时前
python文件中导入另外一个模块这个模块
python
永远是夏天2 小时前
Python面向对象编程(OOP)全教程:从入门到实战(附案例)
python
动感小麦兜2 小时前
服务器搭建
linux·服务器·python
Pocker_Spades_A3 小时前
在家写的代码,办公室接着改?Jupyter通过cpolar实现远程访问这么玩
ide·python·jupyter
m5655bj3 小时前
使用 Python 高效复制 Excel 行、列、单元格
开发语言·python·excel