Here's a vector with a vectorized number with NumPy advanced-indexing to select one item per column, given ind row indices per col -
pd.Series(df.values[ind, np.arange(len(ind))], df.columns)
Run Example -
In [107]: ind = [0, 2, 1] # different one than sample for variety ...: cols = ['A','B','C'] ...: df = pd.DataFrame(np.arange(9).reshape((3,3)),columns=cols) ...: In [109]: df Out[109]: ABC 0 0 1 2 1 3 4 5 2 6 7 8 In [110]: pd.Series(df.values[ind, np.arange(len(ind))], df.columns) Out[110]: A 0 B 7 C 5 dtype: int64
Runtime test
Let's compare the sentence with the built-in vectorized lookup > method proposed in the @MaxU solution, and since we see how good the vectorized ones are, let the number of cols be greater -
In [111]: ncols = 10000 ...: df = pd.DataFrame(np.random.randint(0,9,(100,ncols))) ...: ind = np.random.randint(0,100,(ncols)).tolist() ...:
Divakar
source share