Homebrew installs the GNU Core Utilities with the g- prefix, and checking now I see it's available as gshuf.
I see a couple of problems with how it's used in this essay:
cat big_csv.csv | shuf | head -n 50 > sample_from_big_csv.csv
Since shuf's -n option is "output at most COUNT lines", there should be no need for the head: cat big_csv.csv | shuf -n 50 > sample_from_big_csv.csv
In principle this should be faster because there's less I/O, and it should take less memory if shuf implements the -n option using something like reservoir sampling. (EDIT: it does - https://git.savannah.gnu.org/cgit/coreutils.git/tree/src/shu... )Also, since shuf takes a filename, it could be:
shuf -n 50 < big_csv.csv> sample_from_big_csv.csv
However, in terms of data science, don't most CSV files contain a header? Most of mine do, and the example 'data.csv' has the header "var_x".Using "shuf" means there's a very high chance that the sampled CSV file either won't include the header line, or will have it somewhere other than the first line.
Doesn't that mean that most data scientists will rarely use 'shuf' for sampling from CSV files?