9951 explained code solutions for 126 technologies


python-pandasHow to query dataframe using multiple conditions


import pandas as pd

df = pd.DataFrame({
  'phone': ['ip5', 'ip6', 'ip8', 'sms', 'xi'],
  'price': [204, 304, 404, 405, 305]
})

found = df[(df['price'] > 300) & (df['price'] < 400)]ctrl + c
import pandas as pd

load Pandas module

pd.DataFrame

creates Pandas DataFrame object

df['price'] > 300

first expression for filter

df['price'] < 400

second expression for filter

&

logical and to use both expressions for filtering

found

will contain filtered dataframe