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
  • 2,838
  • 2
  • 18
  • 38
ERJAN
  • 22,540
  • 20
  • 65
  • 127

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
  • 451,927
  • 24
  • 239
  • 318
  • @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