liveBook · Manning

Default_rng

As explained in Pandas Workout: 200 exercises to make you a stronger data analyst

default_rng is a NumPy function that constructs a modern pseudorandom number generator.

NumPy’s default_rng constructs a random-number generator object. Calling its integers method produces a NumPy array of random integers, making it useful for creating reproducible data for pandas Series exercises. section 1.3

Generate reproducible integers

Create a generator with a seed, then request ten integers from 70 through 100. The upper bound is exclusive, so use 101 to include 100: g = np.random.default_rng(0); values = g.integers(70, 101, 10). Recreating the generator with seed 0 produces the same sequence, which makes examples and comparisons predictable. section 1.3

g = np.random.default_rng(0)
g.integers(70, 101, 10)       #1

Inspect a concise seeded example that generates ten integers across the required inclusive range. section 1.3

How Pandas Workout: 200 exercises to make you a stronger data analyst covers it

How deep it goes
Explains generator construction, integer generation, bounds, and seeding, but stops short of the generator’s internal algorithm.
Examples
Uses seeded arrays of ten integers and inserts them into a month-indexed Series.
What it assumes
Assumes familiarity with NumPy and pandas Series while demonstrating random generation from the operation level.
What you can do after
Build reproducible NumPy integer arrays and use them to create pandas Series.
How it connects
Connects NumPy, integers, random seeds, and pandas Series.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pandas Workout: 200 exercises to make you a stronger data analyst. The section links point to the parts of the book it draws on.