码迷,mamicode.com
首页 > 编程语言 > 详细

python 数据处理 对txt文件进行数据处理

时间:2019-10-19 17:44:28      阅读:281      评论:0      收藏:0      [点我收藏+]

标签:list   open   col   basic   alt   bsp   结果   txt   pytho   

数据:

技术图片

 

 对txt文件进行数据处理:

txt_file_path = "basic_info.txt"
write_txt_file_path = "basic_info1.txt"
def write_txt_file():
    if os.path.exists(txt_file_path) is False:
        return
    with open(txt_file_path,‘r‘) as r_file:
        for row in r_file:
            list = row.split("\t")
            # print("用\\t分割行的结果:{}".format(list))
            # print("待分割的列:{}".format(list[2]))
            col = list[2]
            res = col[2:-2].split(‘|‘)
            # print("对此列进行分割的结果:{}".format(res))
            #将分割结果写入新的文件中
            with open(write_txt_file_path,‘a‘) as w_file:
                w_file.write(‘ ‘.join(res))
                w_file.write(‘\n‘)
            #break

if __name__ == "__main__":
    write_txt_file()

  

python 数据处理 对txt文件进行数据处理

标签:list   open   col   basic   alt   bsp   结果   txt   pytho   

原文地址:https://www.cnblogs.com/jiaxinwei/p/11704561.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!