Average period of the decimal expansion of reciprocals of prime numbers Let $P(n)$ be the period of the decimal expansion of $1/n$, for prime $n$ (e.g. $1/7=0.\overline{142857}\rightarrow P(7)=6$). The value of $P(n)$ fluctuates heavily, but it seems to have an average behavior that is more easily visible by considering the function
$$S(x)=\sum_{k=1}^{x}P(p_k)$$
Where $p_k$ is the kth prime. Below is the graph of $S(x)$.

A power regression gives the following approximation with an $R^2$ of $0.9998753$
$$S(x)\approx0.94782x^{2.11976}$$
which would imply that the average value/approximation of $P(p_n)$ around $p_n$ is
$$P(p_n)\approx 0.94782(n^{2.11976}-(n-1)^{2.11976})$$
Is there a way to derive this behavior other than empirically?
This question was inspired by another similar problem related to the Collatz conjecture.
 A: Excellent question. I've provided some relevant literature (with a description of how to go about finding it) and a potential bound that seems to match yours numerically.
First, and for general advice, this is exactly the type of question that is well-suited to a literature search starting with the OEIS, as it. . .

*

*. . . pertains to a sequence . . . that is in integers.


*. . . is a question that is natural to ask and simple to communicate.


*. . . has a rather pure, number theoretic flavor (i.e., focusing on numbers/objects/algorithms themselves and their properties, divorced from any specific contexts).


*. . . admits a sufficiently unique sequence for the search to be direct.
After finding a relevant OEIS sequence, a literature search can become far easier, since the OEIS page itself can cross-reference literature but also since the OEIS index can grant a convenient term to refer to the problem when searching elsewhere (search engines, scholar, MSE, MO, approach0, etc.)
And indeed, after searching the first few terms, we are successful and find the sequence to be OEIS Sequence A002371. We can then cross-reference to earlier literature, which may have been cited by later work. We may find that George Salmon and William Shanks studied the sequence in the late 19th century. With this in mind, we may find a Scholar link to Shanks' paper  with 5 citations, including Knudsen, The Discovery of a Periodic Table of the Prime Numbers, which explores the categorization of the primes by their period length (and which I regrettably lack access to read). Hopefully, you find this literature useful.
For a crude attempt to describe the asymptotic of your sequence, the length of the period for prime $p$ can be shown to be at most $p-1$ (or otherwise a divisor of that), as in MSE Q3545702. So then, the sum of period lengths for primes up to $n$ has, in the worst case, the following upper bound.*
$$
T(n)=\sum_{p\,\text{prime}\\p\le n} P(p) \le \sum_{p\,\text{prime}\\p\le n} (p-1)
\sim \frac{n^2}{2\log n}
$$
where the asymptotic to the sum is given by partial summation and the PNT, as in MO Q63412, and observing that the $-1$ term becomes $\pi(n)\sim \frac{n}{\log n}$ and vanishes.
* For convenience, I've recast your $S(x)$ (taken up to the index $x$ of the last  included prime $p_x$) as $T(n)$ (taken up to an integer bound on the last included prime, $n\ge p_x$), so that we have $\displaystyle T(p_x)=\sum_{p\,\text{prime}\\p\le p_x} P(p)=S(x)$, and we should thus loosely expect $T(x\log x)\approx S(x)$ by the PNT. Then, the above worst case upper bound becomes $S(x)\le\ldots\sim \frac{\left(x\log x\right)^{2}}{2\log\left(x\log x\right)}$, which matches your $0.94782x^{2.11976}$ power approximation remarkably well (Desmos).
A: The value of $P(p_n)$ is always $\frac{p_n-1}{k}$ for some integer $k$. Then, the expected value of $P(p_n)$ is given by
$$P(p_n)\sim\sum_{k=1}^{\infty}r_k\cdot\frac{p_n-1}{k}$$
Where $r_k$ is the proportion of primes that satisfy $P(p_n)=\frac{p_n-1}{k}$. Simplifying the expression gives
$$P(p_n)\sim(p_n-1)\sum_{k=1}^{\infty}\frac{r_k}{k}$$
The values of $r_k$ seem to not be a solved problem in mathematics. There are some articles, such as this one, that address this subject. The first value, $r_1$, is known as Artin's Constant, and is about $0.374$. By numerically calculating, the value of the above sum appears to be $0.577\pm0.001$. These results match what @eyeballfrog pointed out in the comments.
With respect to the function  $S(x)$,
$$S(x)\sim\left(\sum_{k=1}^{\infty}\frac{r_k}{k}\right)\sum_{n=1}^{x}(p_n-1)$$
The above expression matches the calculated values remarkably well.
As also mentioned in Jam's answer, a rough approximation can be given by the Prime Number Theorem:
$$S(x)\approx0.577\left(\frac{(x\ln(x))^2}{2\ln(x\ln(x))}-\frac{x}{\ln(x)}\right)$$
Though it seems that this is a really bad approximation. Replacing $0.577$ by $\approx0.145$ gives much better results
