Idea of Mean or Expectation value from statistical to probability theory 
Mean of a random variable $X$, the expectation value of $X$ is defined as
  $$
\operatorname E(x)=\mu=\sum_{i=1}^n x_i p_i=x_1 p_1+x_2 p_2+\cdots+x_n p_n
$$

Can I have a derivation of this formula from the statistical definition of mean ?
My Understanding
The mean of a statistical data is defined as
$$
\bar{x}=\frac{\sum_{i=1}^n x_if_i}{\sum_{i=1}^n f_i} = \frac{\sum_{i=1}^n x_i f_i} n
$$
The first expression defines the mean of data points that could be obtained if we perform a random experiment, ie. mean obtained from theoretical predictions using probability theory, and the later expresses the mean of the data points obtained after performing a random experiment, ie. mean obtained after the random experiment is performed. Please correct me if I am wrong !
My Attempt
Consider a random experiment and $X$ is a random variable taking values $\{x_1, x_2, \ldots, x_n\}$ with probabilities $p_i=P(x_i)$ and we are conducting $n(S)=N$ independent trials and the outcomes of the experiment are $\{ x^1, x^2, \ldots, x^N\}$.
$$
p_i =\frac{n(x_i)}{n(S)}=\frac{n(x_i)}{N}\implies n(x_i)=N p_i
$$
So the frequency of occurrence of $x_i$ is $f_i=N p_i$
$$
\bar{x}=\frac{\sum_{j=1}^n x^j} N = \frac{\sum_{i=1}^nf_i x_i} N \approx \frac{\sum_{i=1}^n N p_i x_i} N = \sum_{i=1}^n p_i x_i = \operatorname E(X)
$$
Is there a better explanation/derivation of the expression of the expectation value in probability theory or how else one can show both expression mean the same thing ?
 A: If I understand you correctly, then you are asking a rather difficult question. 
Given a sequence of iid samples $X_1,X_2,\dots$ from a discrete random variable $X$,let $\overline X_n=(X_1+\dots+X_n)/n$ be the sample means of the first $n$ samples, and $E[X]=\sum_{i} p_i x_i$, where $x_i$ are the possible values of $X$. You are trying to prove that
$$
\overline X_n\approx EX
$$
This approximation can only hold when $n$ is large. There are two ways I can think to interpret this:


*

*$\overline X_n$ is a random variable which is tightly concentrated around $EX$. This is easy to prove, provided $\def\V{\operatorname{Var}}\V X$ exists; straightforward calculations show $E\overline X_n=EX$ and $\V \overline X_n=\frac1n \V X$. This result is known as the Weak Law of Large Numbers. 

*As $n\to\infty$, the observations $\overline X_n$ will converge to $EX$. This is known as the Strong Law of Large Numbers, and is a bit difficult to prove.
A: If you look around in mathematics, we actually use the word "mean" for quite a few things: the arithmetic mean of a list of numbers, the geometric mean, the harmonic mean, the Mean Value Theorem, and perhaps a few others I don't know or didn't think of.
Now in addition to all these other meanings of "mean" we have the expected value (or mean) of a random variable, the sample mean, and the population mean.
The sample mean is just that, the mean (specifically, the arithmetic mean) of the values you found in a sample.
The population mean is a somewhat different kind of thing than the mean of a random variable, because the idea of a population is that it is finite, so you cannot just keep taking larger and larger samples. Eventually you sample the whole population and you cannot get a larger sample; also, when you do that, your sample mean is (by definition) exactly the same as your population mean, not just an estimator of it.
But you can also have a kind of sample mean relative to a random variable: if you observe $n$ independent random variables with the same distribution, the sample mean will tend to be about the same as the mean of the random distribution.
That is, just as you surmised, $\bar x \approx E(X).$
For any reasonably well-behaved random variable (there are some bizarre exceptions),
the larger a sample you take, the more assurance you have of getting a close approximation. You can spend a whole semester in an undergraduate probability course working up toward this fact.
So I would say the definition of expectation in probability theory is independent of sample means in a formal mathematical sense; but it does relate to some ideas about the "real life" meaning of random variables, and it is also true that a sample mean is a good estimator of the expected value of the distribution from which the sample is drawn. So the connection you made is no accident.
