Why does Pearson's $r$ differ from the converted value of $r$ from Cohen's $d$ +-------------+---------+
|    Group    | Anxiety |
+-------------+---------+
| Picture     |      30 |
| Picture     |      35 |
| Picture     |      45 |
| Picture     |      40 |
| Picture     |      50 |
| Picture     |      35 |
| Picture     |      55 |
| Picture     |      25 |
| Picture     |      30 |
| Picture     |      45 |
| Picture     |      40 |
| Picture     |      50 |
| Real Spider |      40 |
| Real Spider |      35 |
| Real Spider |      50 |
| Real Spider |      55 |
| Real Spider |      65 |
| Real Spider |      55 |
| Real Spider |      50 |
| Real Spider |      35 |
| Real Spider |      30 |
| Real Spider |      50 |
| Real Spider |      60 |
| Real Spider |      39 |
+-------------+---------+

I have data set as above, and now I tried to find correlations between Group vs. Anxiety. 
As far as I know, I can calculate Pearson's $r$ for this data, because it has two variable, where one is continuous, and the other is dichotomous categorical (Picture and Real Spider).
Actually, I can get Pearson's $r$ using SciPy (I loaded the data using pandas):
scipy.stats.pearsonr(spiderLong['Group'].apply(lambda x: 0 if x == 'Picture' else 1), spiderLong['Anxiety'])

The resulting $r$ is 0.337. 
However, I found that there is a way to convert Cohen's $d$ to $r$, as below:
$r = \frac{d}{\sqrt{4 + d^2}}$ when sizes of two groups are equal (link)
But, if I calculate $d$ and convert it to $r$, I cannot get same result as 0.337, rather 0.325. 
I don't know why these two results are different. Actually, I cannot understand the number, '4', in the converting equation above. 
Isn't the converted $r$ from $d$ same as Pearson's $r$? Then, how should I interpret the converted $r$?
 A: There are different formulas for Cohen's $d$ and you don't specify which formula you use. So to make things concrete, I follow the conventions used by D. Lakens in [1].
As @mdewey explains, the formula to convert Cohen's $d$ to a correlation coefficient $r$ gives the point-biserial correlation, not Person's correlation.
However, this is not the reason your calculation doesn't work out as the Pearson's correlation between the two samples concatenated into one and a binary indicator variable for group membership is equal to the point-biserial correlation. That is, you compute $r$ correctly.
The issue is (I'm guessing here since you don't say how you calculate $d$) the bias-correction term in the formula to convert $d$ to $r$. In the linked document the formula is given as:
$$
r = \frac{d}{\sqrt{d^2 + a}},
$$
where $a$ is a correction factor:
$$
a = \frac{\left(n_1 + n_2\right)^2}{n_1n_2}.
$$
If the sample sizes are equal, $n_1 = n_2$, then $a = 4$.
In [1] the formula for the correction factor is instead:
$$
a = \frac{\left(n_1 + n_2-2\right)\left(n_1+n_2\right)}{n_1n_2}.
$$
This version of $a$ converges to 4 as $n_1=n_2 \rightarrow \infty$.
Which is the "right" formula? Well, it depends on how you compute Cohen's $d$ in the first place: Do you correct for computing the two sample means by subtracting 2 or not?
import numpy as np
import scipy.stats

x1 = [30, 35, 45, 40, 50, 35, 55, 25, 30, 45, 40, 50]
x2 = [40, 35, 50, 55, 65, 55, 50, 35, 30, 50, 60, 39]
n1, n2 = len(x1), len(x2)
g = np.repeat([0, 1], [n2, n1])

scipy.stats.pearsonr(
    np.concatenate([x1, x2]),
    g
)[0]
# 0.337439

# Sample means and sums of squares for the two groups separately
mu1, mu2 = np.mean(x1), np.mean(x2)
SS1, SS2 = np.sum((x1 - mu1)**2), np.sum((x2 - mu2)**2)

Cohen's d is the sample standardized mean difference. Let's not apply bias correction to calculate $d$.
d = (mu2 - mu1) / np.sqrt((SS1 + SS2) / (n1 + n2))
# Convert Cohen's d to the point-biserial correlation r: the bias uncorrected version
d / np.sqrt(d**2 + (n1 + n2)**2 / (n1 * n2))
#> 0.337439

Let's apply bias correction to Cohen's $d$.
d = (mu2 - mu1) / np.sqrt((SS1 + SS2) / (n1 + n2 - 2))
# Convert Cohen's d to the point-biserial correlation r: the bias corrected version
d / np.sqrt(d**2 + (n1 + n2 - 2) * (n1 + n2) / (n1 * n2))
#> 0.337439

[1] Lakens D. Calculating and reporting effect sizes to facilitate cumulative science: a practical primer for t-tests and ANOVAs. Frontiers in Psychology. 2013 Nov;4:863. DOI:10.3389/fpsyg.2013.00863. 
