1
        domain          intents  expressionId                     name
0           []               []             8  When I dare to be powerful – to use my strengt...
1           []               []             7  When one door of happiness closes, another ope...
2           []               []             6  The first step toward success is taken when yo...
3           []               []             5                  Get busy living or get busy dying
4  [financial, education]    [resolutions]  4  You know you’re in love when you can’t fall as...
5  [financial, business]     [materialistic]3                         Honesty is the best policy

Here is my dataframe which is having the domain column with list of strings. And, what I want is to fetch only rows that are having 'domain' contains 'financial'(domain==financial), so that I get the below results:

        domain          intents  expressionId                     name
4  [financial, education]    [resolutions]  4  You know you’re in love when you can’t fall as...
5  [financial, business]     [materialistic]3                         Honesty is the best policy

What I have tried so far is with the below command:

df['domain'].map(lambda x: 'financial' in x)

This is returning, the column with objectType as 'bool'.

0    False
1    False
2    False
3    False
4     True
5     True
Name: domain, dtype: bool

But what I want is the filtered result not the bool values.

Please help me with this. Thank you.

3 Answers 3

1
dfFinaicals = df[df['domain'].map(lambda x: 'financial' in x)] 

This is just asking the domain and using it to select the rows. You were almost there.

dfFinaicals = df[df['domain'].contains('financial')]

is more elegant

Sign up to request clarification or add additional context in comments.

1 Comment

First approach worked for me. Getting error for second one. AttributeError: 'Series' object has no attribute 'contains'
1

df[df.domain.apply(lambda v: 'financial' in v)]

df.domain.contains('financial') didn't work for me.

Comments

0

Without actually trying to make your dataframe, I would suggest:

new_df = old_df[old_df['domain'] == 'financial']

2 Comments

I don't know why it didn't write it in code format, just eliminate the ''' '''.
im getting empty Dataframe for this approach.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.