Python_txttocsv

import numpy as np
import pandas as pd
import networkx as nx
import matplotlib.pyplot as plt
import os,sys
import re
import random
data=open('test.txt','r')
textA_csv = []
textB_csv = []
label_csv = []
for line in data:
    if not line:
        break
        pass
    # textA,textB,label = [str(k) for k in line.split("\t")]
    #--------------------------------------------------------------------
    #--------------------------------------------------------------------
    #--------------------------------------------------------------------
    '''
    textA_file = line.split("\t")[0]
    textB_file = line.split("\t")[1].split("\n")[0]
    f_textA_file=open("textA_file.txt", "a+")
    new_context = textA_file + '\n'
    f_textA_file.write(new_context)
    f_textB_file=open("textB_file.txt", "a+")
    new_context = textB_file + '\n'
    f_textB_file.write(new_context)
    '''
    #--------------------------------------------------------------------
    #--------------------------------------------------------------------
    #--------------------------------------------------------------------
    textA = line.split("\t")[0].replace(" ", "")
    textB = line.split("\t")[1].split("\n")[0].replace(" ", "")
    # textB = line.split("\t")[1].replace(" ", "")
    # label = line.split("\t")[2].split("\n")[0].replace(" ", "")
    label = "0"
    textA_csv.append(textA)
    textB_csv.append(textB)
    label_csv.append(str(label))
A=pd.Series(textA_csv,name='A')
B=pd.Series(textB_csv,name='B')
L=pd.Series(label_csv,name='L')
lll=pd.concat([A,B,L],axis=1)
lll.to_csv('test.csv')


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值