#选择矩阵中每行最大的前x个值所在的位置。
import pandas as pd
from pandas import DataFrame,Series
import numpy as np
arr=np.array([[3,1,4],[5,4,3],[3,4,5]])
data=DataFrame(arr,columns=['l1','l2','l3'],index=['u1','u2','u3'])
d={}
for i in range(data.shape[0]):
for j in range(data.shape[1]):
if data.values[i,j]==data.max(1).values[i]:
d[data.index[i]]=[data.columns[j]]
data.values[i,j]=-1
break
t=1
x=2
while t < x:
for i in range(data.shape[0]):
for j in range(data.shape[1]):
if data.values[i,j]==data.max(1).values[i]:
d[data.index[i]].append(data.columns[j])
data.values[i,j]=-1
break
t+=1