如果在熊猫中声明-Python

我有一个这样的数据框:

TechId  Rating  Category LateNight  Weekend  Weekdays 
  001     5      Teacher      1         1       0
  002     4      Student      0         1       1
  003     3      Driver       1         0       1
  004     1      Teacher      1         0       1
  005     1      Student      1         1       0
  006     0      Teacher      1         1       1
  007     2      Teacher      0         0       1

我想查找类别=教师在工作日是否可用,应该在输出中显示TechID 003,006&007。

我尝试了这段代码,

Category = int(input("Enter the Trade ID you want technicians in:"))
Latenight = int(input("Press 1 if you want technicians in Latenight/else press 0:"))
Weekends = int(input("Press 1 if you want technicians in Weekends/else press 0:"))
WeekDays = int(input("Press 1 if you want technicians in WeekDays/else press 0:"))

df2 = df1_new[(df1_new['Category'] == Category) &(df1_new['Weekends'] == Weekends) & (df1_new['LateNight'] == Latenight)]
df2 = df1_new[(df1_new['Category'] == Category) &(df1_new['WeekDays'] == WeekDays) & (df1_new['LateNight'] == Latenight)]
df2 = df1_new[(df1_new['Category'] == Category) &(df1_new['WeekDays'] == WeekDays) & (df1_new['LateNight'] == Latenight) & (df1_new['Weekends'] == Weekends)]
df2_new= df2.sort_values(by=['divcount'], ascending=False)
df2_new.head()

Enter the Category you want : Teacher      
Press 1 if you want technicians in Latenight/else press 0:0
Press 1 if you want technicians in Weekends/else press 0:0
Press 1 if you want technicians in WeekDays/else press 0:1

但这仅显示TechID 007行。某些TechID可能在周末和工作日均可用。那也应该考虑。 谁能帮我吗?

评论