python 數據處理 對txt文件進行數據處理


數據:

 

 對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()

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM