I am doing some research in number theory(High school-so nothing advanced). During this I came across this post.
I have not done much statistics. So could someone explain to me why if $\displaystyle \sum_{n≤x} f(n)=g(x)$, then $E=\dfrac{\mathrm{d}}{\mathrm{d}x}g(x)$.
Suppose $g(x) = \sum_{n \leq x} f(n)$ denotes the partial sums of the arithmetic function $f(x)$. Then the heuristic in the post you mention follows from the intuitive idea behind the derivative.
That is, consider $g(M) - g(N)$, the sum of the last $(M-N)$ elements in the partial sum of $f(n)$. If we're interested in the average size of $f(n)$, then we are exactly interested in $$ \frac{g(M) - g(N)}{M - N} \approx f(N).$$ So you can allow $M \to N$, giving roughly $$ \mathop{Let}_{M \to N} \frac{g(M) - g(N)}{M - N} \approx g'(N),$$ and so $$ g'(N) \approx f(N).$$ For suitably nice arithmetic functions $f$ (being positive is a good start), this heuristic can be argued (perhaps in a different way) and proved. In the post you link to, Tim Gowers was looking more for heuristics than strong proofs, and neither of his two lines of reasoning constitute a full proof.