Pandas Boolean index-select row data through multiple conditional Boolean operations

demand

Select the row data in the DataFrame through the & | operation of multiple conditions

method

source data:

StuID Type on one
0 111021 Math 89
1 111021 English 93
2 312983 English 91
3 314621 English 82
4 314621 Math 92
5 112341 Math 82

Filter conditions:

  1. StuID = 111021
  2. Num > 90
  3. Show only the Num column
    Method:
df.loc[(df['StuID']==111021)&(df['Num']>90),['Num']]

result

Insert picture description here

Guess you like

Origin blog.csdn.net/u013894391/article/details/104526090