04 Missing value given the mean
04 Missing value given the mean#
%%html
<iframe width="700" height="400" src="https://www.youtube.com/embed/qpbaglogObM/" frameborder="0" allowfullscreen></iframe>
import numpy as np
import pandas as pd
from pandas import Series, DataFrame
import matplotlib.pyplot as plt
x = np.array([5, 2, 2, 4, 8])
sum_num_total = len(x) + 1
sum_total_ = x.sum() # + ? missing
mean = 4
# sum_total/sum_num_total = mean
# sum_total = mean * sum_num_total
missing = mean * sum_num_total - sum_total_
print(missing)
3
# double check
y = np.append(x, [missing])
y.sum() / len(y)
4.0
y.mean()
4.0