Why do I have to specify the dataframe twice while selecting rows with logical statements in Pandas?

Viewed 28

I'm not sure what the reason might be for having to specify the name of the dataframe twice when selecting rows using conditional statements in Pandas. For example, if I have a dataframe df:

name age
Alice 31
Bob 21

when I want to select rows with people over 30 I have to write over_thirty = df[df.age > 30]. Why not simply df['age' > 30]]?

2 Answers

so if you write df[age>3] it will give you output in true or false. I am sure which you not needed

Related