This question already has answers here:
How are iloc, ix and loc different?
                                
                                    (3个答案)
                                
                        
                        
                            Selection with .loc in python
                                
                                    (4个答案)
                                
                        
                                2年前关闭。
            
                    
如果我有一个像这样的熊猫数据框:

   A  B  C  D  E
1  3  4  2  5  1
2  5  4  2  4  4
3  5  1  8  1  3
4  1  1  9  9  4
5  3  6  4  1  1


并想找到一个行值为3且列值为D的值,我该怎么做呢?

在这种情况下,我的行值为3,列值为D,在这种情况下如何获得1的收益?

或者,如果我有2的行值和B的列值,我将如何获得4的回报?

最佳答案

您可以使用DataFrame.loc:df.loc[row, 'col_name'],例如df.loc[2, 'B']表示4

关于python - 如果您知道使用 Pandas 数据框的列值和行值,如何检索数据? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52657676/

10-12 22:41