def readwrite1( input_file,output_file): f = open(input_file, 'r') out = open(output_file,'w') print (f) for line in f.readlines(): a = line.split(",") x=a[0] + "," + a[1]+"\n" out.writelines(x) f.close() out.close()
def getRunTimes( fun ,input_file,output_file): begin_time=int(round(time.time() * 1000)) fun(input_file,output_file) end_time=int(round(time.time() * 1000)) print("读写运行时间:",(end_time-begin_time),"ms") getRunTimes(readwrite1,input_file,output_file) #直接撸数据 getRunTimes(readwrite2,input_file,output_file1) #使用dataframe读写数据
读写运行时间: 976 ms
读写运行时间: 777 ms
input_file 大概有27万的数据,dataframe的效率比for循环效率还是要快一点的,如果数据量更大些,效果是否更明显呢?
下面试下增加input_file记录的数量试试,有如下结果
input_file readwrite1 readwrite2 27W 976 777 55W 1989 1509 110W 4312 3158从上面测试结果来看,dataframe的效率提高大约30%左右。
相关推荐:
利用 python 对目录下的文件进行过滤删除实例详解
浅谈Python NLP入门
实例讲解python用户管理系统
以上就是Python读csv文件去掉一列后再写入新的文件技术教程的详细内容,更多请关注Gxl网其它相关文章!
查看更多关于Python读csv文件去掉一列后再写入新的文件技术教程的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did84347