Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在这里按照这个线程从一个非常大的文件中随机打乱数据。正如该线程中所指出的, shuf 会耗尽内存并花费很长时间。所以我最终使用了 perl 命令 perl -ne 'print if (rand() < .01)' huge_file.csv > sample.csv 并且工作效率很高。但是,我注意到它选择了重复的行。我想知道是否有任何方法可以将替换设置为 False 以防止这种情况发生?
perl -ne 'print if (rand() < .01)' huge_file.csv > sample.csv
如果你的源数据有重复的行,那一点 perl 只能打印重复。你可以用类似的东西删除它们
sort -u bigfile.csv | perl -ne 'print if (rand() < .01)' > sample.csv
sort非常擅长对大文件进行排序而不会占用所有内存。您还可以在选择具有相似的随机样本行后删除重复项
sort
perl -ne 'print if (rand() < .01)' bigfile.csv | sort -u > sample.csv