Ciaren

Sample rows

Sample rows — sampleRows

Take a reproducible random sample. A seed is required so the same rows are selected on every run — important for pipelines you preview, schedule, or export.

Before
idnamescore
1Alice88
2Bob72
3Carol95
4Dave61
5Eve79
6Frank84
7Grace91
7 rows · 3 cols
Sample rows (frac=0.4, seed=42)
After
idnamescore
3Carol95
6Frank84
1Alice88
3 rows · 3 cols

Use cases

  • Build a small, representative subset for quick iteration.
  • Down-sample a large dataset before an expensive step.

Configuration

Config keyTypeRequiredDescription
nintConditionalNumber of rows (use this or frac)
fracfloatConditionalFraction in (0, 1]
seedintYesRandom seed — required so the sample is reproducible

Provide exactly one of n or frac. The seed must be an integer; a sample without one is rejected so runs stay reproducible.

Generated Python code

df_2 = df_1.sample(frac=0.4, random_state=42)

Tips & common mistakes

  • The seed is required: it's what makes a scheduled or exported flow sample the same rows every run. Change it to draw a different (but still repeatable) sample.
  • For a positional slice (top N) rather than a random one, use Limit rows.

See also