03 Probability with discrete random variable example#

%%html
<iframe width="700" height="400" src="https://www.youtube.com/embed/d2STHFVHGAg/" frameborder="0" allowfullscreen></iframe>
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
import matplotlib.pyplot as plt
import seaborn as sns

khanacademy

Probability with discrete random variable example fig 1

df = DataFrame({'X = # of packs': ['P(X)'], '1': [0.2]}).set_index('X = # of packs')
df
1
X = # of packs
P(X) 0.2
df['2'] = (1 - df['1']) * 0.2
df
1 2
X = # of packs
P(X) 0.2 0.16
df['3'] = (1 - (df['1'] + df['2'])) * 0.2
df
1 2 3
X = # of packs
P(X) 0.2 0.16 0.128
df['4'] = (1 - (df['1'] + df['2'] + df['3']))
df
1 2 3 4
X = # of packs
P(X) 0.2 0.16 0.128 0.512
df['Total'] = df.sum(axis=1)
df
1 2 3 4 Total
X = # of packs
P(X) 0.2 0.16 0.128 0.512 1.0