Spearman correlations between Numpy array and every Pandas DataFrame row
Since Spearman correlation is the Pearson correlation coefficient of the ranked version of the variables, it is possible to do the following:


Replace values in df rows with their ranks using pandas.DataFrame.rank() function.
Convert v to pandas.Seriesand use pandas.Series.rank() function to get ranks.
Use pandas.corrwith() function to calculate Spearman correlation - Pearson correlation on ranked data.

import pandas as pd
import numpy as np
from scipy.stats import spearmanr

n_rows = 2500
cols = ['a', 'b', 'c', 'd', 'e', 'f', 'g']

df = pd.DataFrame(np.random.random(size=(n_rows, len(cols))), columns=cols)
v = np.random.random(size=len(cols))

# original implementation
corr, _ = zip(*df.apply(lambda x: spearmanr(x,v), axis=1))
corr = pd.Series(corr)

# modified implementation
df1 = df.rank(axis=1)
v1 = pd.Series(v, index=df.columns).rank()
corr1 = df1.corrwith(v1, axis=1)



Calculation time of the modified version:

    %%timeit
    v1 = pd.Series(v, index=df.columns).rank()
    df1 = df.rank(axis=1)
    corr1 = df1.corrwith(v1,axis=1)
    &gt;&gt; 495 ms ± 13.4 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)


Checking corr and corr1 for equality proves that the results are the same:

    print(corr.var()-corr1.var(), corr.mean()-corr1.mean(), corr.median()-corr1.median())
    &gt;&gt; (0.0, 0.0, 0.0)