百万数据CSV文件对比及处理

set() 没有顺序,遍历速度快,值具有唯一性

old.csv    600万条记录

compare.csv  600万条记录

读文件:0.0005s

old_csv = open('old.csv')    #80bytes,#生成器

转化为可读数据结构(set()):600万条数据,17.03s

old_set = set()

for line in db_reader:

        old.set.add(line[4])

转化为可读数据结构(list):600万条数据,15s

old_list = []

for line in db_reader:

        old.set.append(line[4])

遍历:

for _ in old_list:    #0.078s

    continue

for _ in old_set:    #0.56s

    continue


if 'a' in old_set:    #9.5 -07s

    pass

if 'a' in old_list:   #0.066s

    pass

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 6,398评论 0 10
  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 7,741评论 0 23
  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 9,121评论 0 13
  • 我不是白雪公主 也不是白马王子 我只是重庆森林里的一朵蘑菇 晴天 享受阳光的临幸 雨天 吮吸甘甜的雨露 我 生来喜...
    陈瑜_阅读 102评论 0 3
  • 像设计师一样思考,经常自省看看自己是否找到了真正的问题,好问题并不代表自己真正面对的问题。在设计人生的过程中,如果...
    嗯哼嗯哼酱阅读 166评论 0 0