df = pd.DataFrame({'A':list('abcdef'),
'B':[4,5,4,5,500,4],
'C':[7,8,9,4,2,3],
'D':[1,300,5,7,1,0],
'E':[5,3,6,9,2,4],
'F':list('aaabbb')}, index = [1] * 6)
df.columns = ['A'] * 6
print (df)
A A A A A A
1 a 4 7 1 5 a
1 b 5 8 300 3 a
1 c 4 9 5 6 a
1 d 5 4 7 9 b
1 e 500 2 1 2 b
1 f 4 3 0 4 b
a = np.where(df == 500)[0]
b = np.where(df == 300)[1]
print (a)
[4]
print (b)
[3]
c = df.iloc[a[0],b[0]]
print (c)
1
但是如果应该复制值是可能的,那么只选择第一次出现的值,因为np.where返回带有{}的数组:
^{pr2}$
a = np.where(df == 2)[0]
b = np.where(df == 5)[1]
print (a)
[4 4]
print (b)
[4 1 3 1]
c = df.iloc[a[0],b[0]]
print (c)
2
如果值} 选择:
search_row
和search_column
在所有数据中都是唯一的,则使用np.where
作为位置,并按^{但是如果应该复制值是可能的,那么只选择第一次出现的值,因为}的数组:
^{pr2}$np.where
返回带有{相关问题 更多 >
编程相关推荐