python下处理win和linux分行符

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/fjssharpsword/article/details/90511967

场景:linux只用\n换行,win下用\r\n表示换行。linux正常的一行在win下分多行,linux下在字符串中替换\r\n,在win中正常。

#linux只用\n换行,win下用\r\n表示换行。linux正常的一行在win下分多行,在字符串中替换\r
import pandas as pd
import numpy as np
data = pd.read_csv("/data/fjsdata/mededp/medallN.csv",sep='|',low_memory=False)#iterator=True
data['queCon']=data['queCon'].apply(lambda x:x.replace('\r','').replace('\n',''))#替换win下的分行符
data['queAnsA']=data['queAnsA'].apply(lambda x:x.replace('\r','').replace('\n',''))#替换win下的分行符
data['queAnsB']=data['queAnsB'].apply(lambda x:x.replace('\r','').replace('\n',''))#替换win下的分行符
data['queAnsC']=data['queAnsC'].apply(lambda x:x.replace('\r','').replace('\n',''))#替换win下的分行符
data['queAnsD']=data['queAnsD'].apply(lambda x:x.replace('\r','').replace('\n',''))#替换win下的分行符
data['queAnsE']=data['queAnsE'].apply(lambda x:x.replace('\r','').replace('\n',''))#替换win下的分行符
data['quePar']=data['quePar'].apply(lambda x:x.replace('\r','').replace('\n',''))#替换win下的分行符
#data = data.get_chunk(10)
print(data.shape)
print(data.head())
data.to_csv("/data/fjsdata/mededp/medallNN.csv",index=False,sep='|')

 

展开阅读全文

没有更多推荐了,返回首页