DATA MUNGING PYTHON PANDAS DATAFRAME PANDAS DATAFRAME TUTORIAL

How to search a value within a Pandas DataFrame row?

This recipe helps you search a value within a Pandas DataFrame row
In [1]:
## How to search a value within a Pandas DataFrame row
def Snippet_107():
    print()
    print(format('How to search a value within a Pandas DataFrame row','*^82'))

    import warnings
    warnings.filterwarnings("ignore")

    # load libraries
    import pandas as pd

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

    # select certaim row in a Pandas DataFrame
    print(); print(df[df['country'].map(lambda country: 'Syria' in country)])

Snippet_107()
***************How to search a value within a Pandas DataFrame row****************

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

    name           country
0  Jason  [Syria, Lebanon]


Companies using this Recipe
1 employee of Ericsson
1 employee of Altimetrik
1 employee of HCL Technologies
1 employee of ANAC
1 employee of ICU Medical
1 employee of eClerx
1 employee of Renovite Technologies