2

Below I have a DataFrame and I want to get simply a sub-category of dataframe , which consist of only those records for which column("day") will be ' friday ' and for non-smokers only . BAsically I want to calculate a boxplot for non-smoker's total_bill at friday . But I need to get a sample from whole df , as I have to calculate it for other also and maybe even more conditions to specify.

df.head()

     total_bill     tip   sex    smoker  day    time    size
 0   16.99          1.01  Female    No  Sun    Dinner   2
 1   10.34          1.66    Male    No  Sun    Dinner   3
 2   21.01          3.50    Male    No  Sun    Dinner   3
 3   23.68          3.31    Male    No  Sun    Dinner   2
 4   24.59          3.61  Female    No  Sun    Dinner   4
Ali
  • 35
  • 1
  • 5

1 Answers1

2

You can use .loc to access the dataframe with your two conditions, and add additional conditions as needed.

df[(df.day =="Fri") & (df.smoker == "No")]
Derek O
  • 16,770
  • 4
  • 24
  • 43
  • 2
    Thanks @Derek , it works and actually helped me a lot . – Ali Oct 08 '20 at 09:10
  • Glad to hear it helped! If you want to accept the answer, that might help people having a similar issue as yourself :) – Derek O Oct 08 '20 at 17:56