In Python, a common way to filter a data frame is like this
df.loc[(df['field 1'] == 'a') & (df['field 2'] == 'b'), 'field 3']...
When df
name is long, or when there are more filter conditions (only two in the above), the above line will be long naturally. Moreover, it is a bit tedious to have type out df
name for each condition. In R or SQL, we don't really need to do that. So, my question is if there is a way to shorten the above line in Python. For example, is there a way that I don't have to write down df
name in each condition? Thanks.