-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Add some examples of using pandas dataframe.query, probably to the filtering rows section of the chapter about row operations.
https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.query.html
AI example:
import pandas as pd
# Create a sample DataFrame
df = pd.DataFrame({
'name': ['john', 'david', 'anna', 'peter'],
'country': ['USA', 'UK', 'USA', 'UK'],
'age': [23, 45, 45, 30]
})
target_age = 45
# Query for rows where country is 'USA' and age is greater than 30
result = df.query("country == 'USA' and age > 30")
# Query using an external Python variable
result_var = df.query("age == @target_age")
print(result)
print(result_var)
Metadata
Metadata
Assignees
Labels
No labels