9951 explained code solutions for 126 technologies


python-pandasHow to filter dataframe by column value


import pandas as pd

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

found = df[df['price'] > 304]ctrl + c
import pandas as pd

load Pandas module

pd.DataFrame

creates Pandas DataFrame object

'price'

column name to filter based on

df['price'] > 304

expression to filter based on (price column values are greater than 304)

df[

filters dataframe based on given expression and returns filtered rows

found

will contain filtered dataframe