Title: Select Rows With A Certain Value
Slug: pandas_select_rows_containing_values
Summary: Select Rows With A Certain Value
Date: 2016-05-01 12:00
Category: Python
Tags: Data Wrangling
Authors: Chris Albon


In [1]:
import pandas as pd

In [2]:
# Create an example dataframe
data = {'name': ['Jason', 'Molly'], 
        'country': [['Syria', 'Lebanon'],['Spain', 'Morocco']]}
df = pd.DataFrame(data)
df


Out[2]:
country name
0 [Syria, Lebanon] Jason
1 [Spain, Morocco] Molly

In [3]:
df[df['country'].map(lambda country: 'Syria' in country)]


Out[3]:
country name
0 [Syria, Lebanon] Jason