Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python(熊猫)-通过匹配列';将值转换为数据帧_Python_Pandas_Dataframe - Fatal编程技术网

Python(熊猫)-通过匹配列';将值转换为数据帧

Python(熊猫)-通过匹配列';将值转换为数据帧,python,pandas,dataframe,Python,Pandas,Dataframe,我有下面假定的数据帧 a b c d e F 0.02 0.62 0.31 0.67 0.27 a 0.30 0.07 0.23 0.42 0.00 a 0.82 0.59 0.34 0.73 0.29 a 0.90 0.80 0.13 0.14 0.07 d 0.50 0.62 0.94 0.34

我有下面假定的数据帧

a       b       c       d       e       F
0.02    0.62    0.31    0.67    0.27    a
0.30    0.07    0.23    0.42    0.00    a
0.82    0.59    0.34    0.73    0.29    a
0.90    0.80    0.13    0.14    0.07    d
0.50    0.62    0.94    0.34    0.53    d
0.59    0.84    0.95    0.42    0.54    d
0.13    0.33    0.87    0.20    0.25    d
0.47    0.37    0.84    0.69    0.28    e
列F表示数据帧的列。 对于F列的每一行,我希望从数据帧的其余部分找到相关的行和列,并将值返回到一列中

结果如下:

a       b       c       d       e       f   To_Be_Filled
0.02    0.62    0.31    0.67    0.27    a   0.02 
0.30    0.07    0.23    0.42    0.00    a   0.30 
0.82    0.59    0.34    0.73    0.29    a   0.82 
0.90    0.80    0.13    0.14    0.07    d   0.14 
0.50    0.62    0.94    0.34    0.53    d   0.34 
0.59    0.84    0.95    0.42    0.54    d   0.42 
0.13    0.33    0.87    0.20    0.25    d   0.20 
0.47    0.37    0.84    0.69    0.28    e   0.28 
我能够用下面的代码识别每种情况,但不确定如何在整个数据帧中进行识别

test.loc[test.iloc[:,5]==a,test.columns==a]
非常感谢

您可以使用:


np.arange(len(df))
可以替换为
df.index

非常感谢你!!这正是我要找的!非常感谢
df['To_Be_Filled'] = df.lookup(np.arange(len(df)), df['F'])
df
Out: 
      a     b     c     d     e  F  To_Be_Filled
0  0.02  0.62  0.31  0.67  0.27  a          0.02
1  0.30  0.07  0.23  0.42  0.00  a          0.30
2  0.82  0.59  0.34  0.73  0.29  a          0.82
3  0.90  0.80  0.13  0.14  0.07  d          0.14
4  0.50  0.62  0.94  0.34  0.53  d          0.34
5  0.59  0.84  0.95  0.42  0.54  d          0.42
6  0.13  0.33  0.87  0.20  0.25  d          0.20
7  0.47  0.37  0.84  0.69  0.28  e          0.28