This question already has answers here:
Logical operators for boolean indexing in Pandas
                                
                                    (3个答案)
                                
                        
                                上个月关闭。
            
                    
low_enrollment = df[ df['total_enrollment'] < 1000 ]
low_enrollment = df[df['sat_score'] < 1000]


如何将它们组合成一行?这是行不通的。

low_enrollment = df[ df['total_enrollment'] < 1000 and df['sat_score'] < 1000]

最佳答案

您应该将&运算符用于逻辑运算符,而不是Python and运算符:

low_enrollment = df[(df['total_enrollment'] < 1000) & (df['sat_score'] < 1000)]

关于python - 如何在 Pandas 中组合数据框选择查询? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59566300/

10-14 17:57
查看更多