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

How can i combine them in one line? This does not work.

low_enrollment = df[ df['total_enrollment'] < 1000 and df['sat_score'] < 1000]
Sreekiran A R
  • 3,123
  • 2
  • 20
  • 41
ERJAN
  • 23,696
  • 23
  • 72
  • 146

1 Answers1

3

You should be using the & operator for logical and, not the Python and:

low_enrollment = df[(df['total_enrollment'] < 1000) & (df['sat_score'] < 1000)]
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • @Erfan I want to learn more about Pandas, but it's hard to get started, because there are many other senior users such as yourself and Jezrael. – Tim Biegeleisen Jan 02 '20 at 16:06
  • @ERJAN Man...it seems that it's very easy to misread a comment, with no facial context of any kind. I actually do want to "break" into Pandas, but, like every other tag, there are gurus like you who are very active. – Tim Biegeleisen Jan 02 '20 at 16:17