Recipe: How to search a value within a Pandas DataFrame row?
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]


Stuck at work?
Can't find the recipe you are looking for. Let us know and we will find an expert to create the recipe for you. Click here
Companies using this Recipe
3 developers from Infosys
1 developer from eClerx
1 developer from HvH
1 developer from Jefferies
1 developer from Vodafone
1 developer from Altimetrik
1 developer from Ericsson
1 developer from ICU Medical
1 developer from Netcore
1 developer from Wipro