在磁盘上而不是内存中对大型csv文件进行排序
csvsorter的Python项目详细描述
CSV分拣机
python 3的csvsort分叉。 用于排序磁盘上不适合内存的csv文件。合并排序算法用于将原始文件分解为较小的块,在内存中对这些块进行排序,然后合并这些排序的文件。
示例用法
>>>fromcsvsorterimportcsvsort>>># sort this CSV on the 5th and 3rd columns (columns are 0 indexed)>>>csvsort('test1.csv',[4,2])>>># sort this CSV with no header on 4th column and save results to separate file>>>csvsort('test2.csv',[3],output_file='test3.csv',has_header=False)>>># sort this TSV on the first column and use a maximum of 10MB per split>>>csvsort('test3.tsv',[0],max_size=10,delimiter='\t')>>># sort this CSV on the first column, force quotes around every field (default is csv.QUOTE_MINIMAL) and use windows-1250 encoding>>>importcsv>>>csvsort('test4.csv',[0],quoting=csv.QUOTE_ALL,encoding='windows-1250')
安装
$ pip install csvsorter