partypy

Package Contents

Functions

simulate_party(p, n_simulations=500)

Simulate guest attendance at a party.

plot_simulation(results)

Plot a histogram of simulation results.

load_party()

Return a dataframe of 100 party guests.

partypy.simulate_party(p, n_simulations=500)[source]

Simulate guest attendance at a party.

The attendance of each guest is treated as a Bernoulli random variable with probability of attendance p. The total number of attending guests is summed up for each n_simulations.

Parameters
  • p (float or array_like of floats) – Probability of guest attendance, >= 0 and <=1.

  • n_simulations (int, optional) – Number of simulations to run. By default, 500.

Returns

DataFrame with total number of guests per simulation.

Return type

pandas.DataFrame

Examples

>>> simulate_party([0.1, 0.5, 0.9], n_simulations=5)
            Total guests
Simulation
1                      2
2                      2
3                      2
4                      2
5                      2
partypy.plot_simulation(results)[source]

Plot a histogram of simulation results.

Parameters

results (pandas.DataFrame) – DataFrame of simulation results from partpy.simulate_party()

Returns

Histogram of simulation results.

Return type

altair.Chart

Examples

>>> from partypy.simulate import simulate_party
>>> from partypy.plotting import plot_simulation
>>> results = simulate([0.1, 0.5, 0.9])
>>> plot_simulation(results)
altair.Chart
partypy.load_party()[source]

Return a dataframe of 100 party guests.

Contains the following fields:

name 100 non-null object probability_of_attendance 100 non-null float

Returns

DataFrame of party guest names and probabilities of attendance.

Return type

pandas.DataFrame

Examples

>>> data = load_party()
>>> data.head()
               name  probability_of_attendance
0    Donovan Willis                       0.70
1   Jocelyn Navarro                       0.70
2     Houston Stein                       0.90
3    Carlos Mullins                       0.50
4    Bridger Pruitt                       0.70