You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/source/cookbook.rst
+36
Original file line number
Diff line number
Diff line change
@@ -1223,6 +1223,42 @@ Computation
1223
1223
`Numerical integration (sample-based) of a time series
1224
1224
<http://nbviewer.ipython.org/5720498>`__
1225
1225
1226
+
Correlation
1227
+
***********
1228
+
1229
+
The `method` argument within `DataFrame.corr` can accept a callable in addition to the named correlation types. Here we compute the `distance correlation <https://en.wikipedia.org/wiki/Distance_correlation>`__ matrix for a `DataFrame` object.
1230
+
1231
+
.. ipython:: python
1232
+
1233
+
defdistcorr(x, y):
1234
+
n =len(x)
1235
+
a = np.zeros(shape=(n, n))
1236
+
b = np.zeros(shape=(n, n))
1237
+
1238
+
for i inrange(n):
1239
+
for j inrange(i +1, n):
1240
+
a[i, j] =abs(x[i] - x[j])
1241
+
b[i, j] =abs(y[i] - y[j])
1242
+
1243
+
a += a.T
1244
+
b += b.T
1245
+
1246
+
a_bar = np.vstack([np.nanmean(a, axis=0)] * n)
1247
+
b_bar = np.vstack([np.nanmean(b, axis=0)] * n)
1248
+
1249
+
A = a - a_bar - a_bar.T + np.full(shape=(n, n), fill_value=a_bar.mean())
1250
+
B = b - b_bar - b_bar.T + np.full(shape=(n, n), fill_value=b_bar.mean())
0 commit comments